Welcome Guest ( Log In | Register )

4 Pages V   1 2 3 > »   
Reply to this topicStart new topic
> Very Simple Password Protection Script, Beginner - Intermediate
Adrian
post May 21 2005, 11:14 AM
Post #1


Addicted Dot
Group Icon
Group: Moderator
Posts: 7,289
Joined: 26-September 04
Member No.: 763





Very Simple Password Protection Script by Adrian
In this tutorial I will teach you how to make a very simple text based password protection script.

View a demo here, use the username user and the password demo.

I will first give you all the files then I'll explain them.
form.html
CODE
<html>
<head>
<title>Login</title>
</head>

<body>
<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>
</body>
</html>

protected.php
CODE
<?php
$user = "your_username_here";
$password = "your_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");
}
?>

I wont explain form.html because its a simple html form but I will explain protected.php.

CODE
$user = "user";
$password = "demo";
This is the code which specifies the username and password. You cannot view these if you go to the protected.php file and press View Source.

CODE
$formuser = $_POST["formuser"];
$formpass = $_POST["formpass"];
These two get the information from the form and puts it into two different variables.

CODE
if(($formuser == $user) && ($formpass == $password)){
This checks to see if the username from the form is the same as the variable specified above and the same for the password.

CODE
}
else {
echo("Login Incorrect, Please click back and try again");
}
The first } closes the if statement. The rest says what will happen if the login is incorrect. In this case the script will write, Login Incorrect, Please click back and try again.

Hope you found this useful. Its a simple tutorial but is useful for small scripts and could be modified to use to cookies for multiple pages.

-Adrian

EDIT: This is an old tutorial. I have made a new one with slightly more features (support for multiple pages, cookies) but it is still a nice simple script. To view it please go to this topic

This post has been edited by Adrian: May 4 2006, 11:43 AM


IPB
 
+Quote Post  Go to the top of the page
*D*
post May 22 2005, 11:46 AM
Post #2


Merry KissMoose
Group Icon
Group: Main Team
Posts: 15,988
Joined: 18-May 04
From: North Pole
Member No.: 2





Thanks Adrian, simple but effective.
 
+Quote Post  Go to the top of the page
exandsix
post May 22 2005, 06:14 PM
Post #3


Getting Used To The Dots
Group Icon
Group: Member
Posts: 27
Joined: 6-May 05
Member No.: 3,813





thanks! looks simple enough to create smile.gif


IPB
 
+Quote Post  Go to the top of the page
Zaigham
post May 23 2005, 05:39 AM
Post #4


13Dots' Friend!
Group Icon
Group: *Premier*
Posts: 501
Joined: 13-July 04
From: Pakistan
Member No.: 400





looks easy to understand,

I'll give it a try, while I m not coder bigwink.gif

Thanks for sharing,

Regards,

Zaigham


IPB
 
+Quote Post  Go to the top of the page
Adrian
post May 23 2005, 07:33 AM
Post #5


Addicted Dot
Group Icon
Group: Moderator
Posts: 7,289
Joined: 26-September 04
Member No.: 763





No problem. Glad to be of help.

-Adrian


IPB
 
+Quote Post  Go to the top of the page
xxandrew76xx
post May 23 2005, 01:46 PM
Post #6


New Member
Group Icon
Group: Member
Posts: 12
Joined: 22-May 05
Member No.: 4,205





Thanks I may incorporate this into my site
 
+Quote Post  Go to the top of the page
RICH15ARD
post May 24 2005, 09:14 AM
Post #7


New Member
Group Icon
Group: Member
Posts: 2
Joined: 17-May 05
Member No.: 4,083



Nice simple tutorial. You ever use Perl instead of PHP?
 
+Quote Post  Go to the top of the page
hooptey
post Jun 9 2005, 02:37 PM
Post #8


New Member
Group Icon
Group: Member
Posts: 3
Joined: 9-June 05
Member No.: 4,582



any good tutorials around using sessions instead of passing poseted variable around?
 
+Quote Post  Go to the top of the page
evanescence-sal
post Aug 12 2005, 09:09 PM
Post #9


New Member
*
Group: Validating
Posts: 19
Joined: 7-August 05
Member No.: 5,944





great tut
 
+Quote Post  Go to the top of the page
Lethal
post Aug 14 2005, 07:28 AM
Post #10


New Member
Group Icon
Group: Member
Posts: 1
Joined: 14-August 05
Member No.: 6,141



Is there a code where you can write to the username and password part?

Like a register code?
 
+Quote Post  Go to the top of the page

4 Pages V   1 2 3 > » 
Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 1st December 2008 - 11:30 PM
Mortgages | Myspace Codes | Pacotes Reveillon Salvador | Send Money Online | Gas Suppliers