PDA

View Full Version : [PHP - Beginner] Simple Secure Login



YouFail
01-08-2006, 12:36 PM
This is my first tutorial so I hope I explain it in enough detail.




<form name="login" method="post" action="protected.php">
Username:
<input name="formuser" type="text" id="formuser">
<br>
Password:
<input name="formpass" type="password" id="formpass">
<br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
</form>


Thats the basic Form that has a submit button etc.
Next make a page called protected.php and enter this code:



<?php
$user = "USERNAME HERE";
$password = "PASSWORD HERE";
$formuser = $_POST["formuser"];
$formpass = $_POST["formpass"];
if(($formuser == $user) && ($formpass == $password)){
//Protected Content here
}
else {
echo("Login Incorrect, Please click back and try again");
}
?>


<?php - Starts the php

$user = "USERNAME HERE"; - That just says that if the username entered is that its true

$password = "PASSWORD HERE"; - That just says that if the password entered is that its true

$formpass = $_POST["formpass"];
if(($formuser == $user) && ($formpass == $password)){
//Protected Content here
}
else {
echo("Login Incorrect, Please click back and try again");
}
?>

Unless you know what your doing dont change anything there except the bit in bold

And voila you have your simple login!

Free
01-08-2006, 12:54 PM
I swear i seen that before

YouFail
01-08-2006, 01:01 PM
Ye it was on Techtuts but I rephrased and tried to explain more

Josh-H
01-08-2006, 01:32 PM
[quote=Respect]This is my first tutorial so I hope I explain it in enough detail.

[quote]

if its off techtuts its not yours.

YouFail
01-08-2006, 01:42 PM
Ye it was on Techtuts but I rephrased and tried to explain more
Sorry shouldnt of said it was mine I should of said it was techtuts reprhased as mine

Mentor
01-08-2006, 02:47 PM
With that theyed have to log in each time the viewed the page "/ although im feeling in a tutoraly mood so i may write one...

Splinter
01-08-2006, 05:48 PM
yep use cookies :)

Want to hide these adverts? Register an account for free!