PDA

View Full Version : Password driven link


brianvoe
08-30-2007, 01:36 PM
I am creating a web page in which when someone has to enter a password to get in. But I want what they type in to decide what page they go to. Example: Let's say I have three passwords that I set up. code123, code876 and code391. when someone types in one of those it will direct them to a specific web page that I have made. Can someone help me figure out how to do this?

laxman
08-31-2007, 08:15 AM
You need to use a server side technology such as PHP or ASP and then you need to use a database technology such as MySQL. PHP and MySQL are free.

Once you have that set up you just use some php code like

you would have a list of passwords in the database and then when a user types in a password, you compare it against all the passwords in the database. then:

if (match is found)
{
go to secure section
}
else
{
go to some other page
}

You will have to use session variables to make sure that users can go to multiple pages and only type in the password once.

So to get this done:

1. Learn the basics of PHP and MySQL (lots of tutorials, look for them on google, also its very easy if you already know programming)

2.Learn about session variables

3.Put it together

If you have dreamweaver, there is a password option there to do it for you. I've never used it, but i've used most of the other PHP stuff and it works quite well.

brianvoe
08-31-2007, 02:45 PM
Is there any way of doing right in the page. I am only using 3 passwords. Do I have to use a database to do this?

laxman
09-01-2007, 03:42 AM
Nope, if you only want three password you do

$pass1 = stuff;
$pass2 = stuff2;
$pass3 = stuff3;

//assume you had a textfield called userInput where the user puts the password
$userInput = $GET_['userInput'];

if ($pass1 = $userInput || $pass2 = $userInput || $pass3 = $userInput)
{
redirect to the correct page
}


You will still need to use session variables so that you can go to different pages without retyping the password. There are some password templates you can download, where all you do is include them at the top of the page you want to protect. You could take one of those and modify it with the if statement above to allow three passwords.