Jump to content

simple .php assignment

SmilesRising

 

I have an assignment that i really need help with, i need to do this:

 

Type a program with a form where you can enter the value of the uid and pwd variables and then send them to the page. There the program should check if uid has the value "admin" and pwd has the value "kanelbulle".

 

Then this text will be printed: Correct password. You have logged in as an administrator Otherwise, the program will print: Incorrect password

 

And i dont know how to do it.. could someone show me how it's done?

 

 

Watches and computers                    

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, kb5zue said:

Sorry, but you will have to do this piece of homework on your own.

Can you at least tell me what to start with. i have the form but i need help with the password thing...

Watches and computers                    

Link to comment
Share on other sites

Link to post
Share on other sites

Try studying the book a little more, the part dealing with variables.

Link to comment
Share on other sites

Link to post
Share on other sites

First thing I'd do is ask why php is still being taught.

 

But really, do your own homework. That problem is really, incredibly simple.

 

Write some code and maybe post if it doesn't work. 

Ryzen 5 1600 @ 3.9 Ghz  | Gigabyte AB350M Gaming 3 |  PaliT GTX 1050Ti  |  8gb Kingston HyperX Fury @ 2933 Mhz  |  Corsair CX550m  |  1 TB WD Blue HDD


Inside some old case I found lying around.

 

Link to comment
Share on other sites

Link to post
Share on other sites

if (strtolower($_POST["uid"])=="admin" and $_POST["pwd"]=="kanelbulle"){

// code when you're entering good login and password

}

else

{

// code when you're not entering good login and password

}

 

It's just a fragment, figure out rest.

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, kb5zue said:

Try studying the book a little more, the part dealing with variables.

 

5 minutes ago, bleedblue said:

First thing I'd do is ask why php is still being taught.

 

But really, do your own homework. That problem is really, incredibly simple.

 

Write some code and maybe post if it doesn't work. 

i dont have a book and i thought this forum was about helping each other...

Watches and computers                    

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, homeap5 said:

if (strtolower($_POST["uid"])=="admin" and $_POST["pwd"]=="kanelbulle"){

// code when you're entering good login and password

}

else

{

// code when you're not entering good login and password

}

 

It's just a fragment, figure out rest.

 

thank you!

Watches and computers                    

Link to comment
Share on other sites

Link to post
Share on other sites

Forms are written in HTML. 

 

The logic and variables are written in PHP. 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, smiles rising said:

 

i dont have a book and i thought this forum was about helping each other...

Write here what you're done so far and I'll help you with rest of the code.

Link to comment
Share on other sites

Link to post
Share on other sites

I have used the example linked below for some simple projects at home; to "get the job done" without a fancy database.

https://www.w3schools.in/php-script/php-login-without-using-database/

 

Im by no means a php programmer, and dont want to sound like an ass, but there seems to be loads of tutorials on Google regarding how to make a login page with PHP. I think the aspect of online forums like this is to help you once you have already started trying things, and got stuck on something in particular that needs further explaining about how it works, or why it doesn't work and what you have tried. Rather than copy/pasting the assignment as the question.

 

If you need to test your code install something like xampp for windows to see if it works.

Link to comment
Share on other sites

Link to post
Share on other sites

On 9/30/2018 at 6:56 AM, smiles rising said:

 

i dont have a book and i thought this forum was about helping each other...

We help each other but it requires a minimum level of effort on your part. Practice your Google Fu skills for a bit and come up with a prototype, if you get stuck somewhere, then ask the forum. If you really can't even think of where to begin, then you honestly shouldn't be taking that course since the majority of development is actually thinking of the solution.

[Out-of-date] Want to learn how to make your own custom Windows 10 image?

 

Desktop: AMD R9 3900X | ASUS ROG Strix X570-F | Radeon RX 5700 XT | EVGA GTX 1080 SC | 32GB Trident Z Neo 3600MHz | 1TB 970 EVO | 256GB 840 EVO | 960GB Corsair Force LE | EVGA G2 850W | Phanteks P400S

Laptop: Intel M-5Y10c | Intel HD Graphics | 8GB RAM | 250GB Micron SSD | Asus UX305FA

Server 01: Intel Xeon D 1541 | ASRock Rack D1541D4I-2L2T | 32GB Hynix ECC DDR4 | 4x8TB Western Digital HDDs | 32TB Raw 16TB Usable

Server 02: Intel i7 7700K | Gigabye Z170N Gaming5 | 16GB Trident Z 3200MHz

Link to comment
Share on other sites

Link to post
Share on other sites

@bleedblue Because Php is still relevant. If you don't like it, make a better CGI scripting/db access lang that gets processed before the page loads (not dynamic). Otherwise, can't help you.

 

@smiles rising You need to start with an algorithm. Divide the task at hand into smaller steps first, and use Php instructions and commands to fill in the gaps (pseudo-code). When you have a possible concept ready, start coding out the final product. Refactor as necessary. 

 

@homeap5 Please use the code tags if possible.

https://linustechtips.com/main/announcement/12-please-use-code-tags/

Link to comment
Share on other sites

Link to post
Share on other sites

Damn you guys are being hard on this guy/gal...

@smiles rising - I hope the code provided by @homeap5 helped you. The highlighted version of the code is here (also testing out my skills with the forum text editor at this point):

 


if (strtolower($_POST["uid"])=="admin" and $_POST["pwd"]=="kanelbulle"){

    // code when you're entering good login and password

} else {

    // code when you're not entering good login and password

}

 

If there is anything about this, let's be honest, relatively, simple if statement, let me and @TopHatProductions115 know. We may be able to give a detailed answer to why some things work as they do :)

A simple software developer from the far away land of Denmark

Link to comment
Share on other sites

Link to post
Share on other sites

In fact login and password should be made different using session (for example) to remember user, then logout option, then... And then we will end with huge code. And I don't know exactly what this program should do, so even if I want to help more, I can give only small hint.

Link to comment
Share on other sites

Link to post
Share on other sites

Here's how I would do your homework:

<?php

// if form is never submitted, these variables are never created, so php would show a
// warning if you try to set the uid and pwd variables. So check if they exist first.
$uid = (isset($_REQUEST['uid']) == TRUE) ? $_REQUEST['uid'] : '';
$pwd = (isset($_REQUEST['pwd']) == TRUE) ? $_REQUEST['pwd'] : '';

// if user clicked login, the name of the button gets submitted along with other parameters
$form_submitted = (isset($_REQUEST['button_login']) == TRUE) ? TRUE : FALSE; 

echo '<!DOCTYPE HTML>
<html>
<head>
<title>My page tile</title>
</head>
<body>';

$showform = TRUE;

if ($form_submitted==TRUE) {
	if (($uid=='admin') && ($pwd=='kanelbulle')) {
		echo '<p>Correct password. You have logged in as an administrator.</p>';
		$showform  = FALSE;
	} else {
		echo '<p>Incorrect Password</p>';
	}
}
// use of <table> is completely optional, used it for quick and dirty "make pretty form" reasons.
if ($showform==TRUE) {
	echo '
	<table>
	<form method="POST" name="formname" action="">

	<tr><td style="width:100px;"><label>UID:</label></td><td><input style="float:left;" name="uid" type="text" value="'.htmlspecialchars($uid).'" /></tr>
	<tr><td style="width:100px;"><label>PWD:</label></td><td><input name="pwd" type="password" value="'.htmlspecialchars($pwd).'" /></tr>
	<tr><td colspan="2" align="right"><input name="button_login" type="submit" value="Login" /></td></tr>

	</form>
	</table>';

}

echo '</body></html>';

?>

Ask questions if something is not clear.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×