Web Hosting Talk







View Full Version : PHP file password protected access


saghir69
10-25-2004, 07:49 AM
ok i've got a php file that logs on to a data base and does a few select queries and displays the the data.

but i want the file to display a

textbox saying enter password, and a submit button.

then if the user enters the right password (a fixed password embedded within the php file)

then the rest of the page can load. otherwise just end the script.

how would i do that?

X-TechMedia
10-25-2004, 08:58 AM
<form method="post" action="thisform.php">
<input type="text" name="password">
<input type="submit" value="Load File">


$secret = 'thisismypassword';

if ($_POST["password"] == $secret) {
// do this if it is ok
} else {
// else die here
}

Burhan
10-25-2004, 09:07 AM
<input type="text" name="password">

should be

<input type="password" name="password" />

LucasDuw
10-25-2004, 10:19 AM
Originally posted by BennyP
<form method="post" action="thisform.php">
<input type="text" name="password">
<input type="submit" value="Load File">


$secret = 'thisismypassword';

if ($_POST["password"] == $secret) {
// do this if it is ok
} else {
// else die here
}


You also need to close the form...

<form method="post" action="thisform.php">
<input type="password" name="password">
<input type="submit" value="Load File">
</form>

X-TechMedia
10-25-2004, 10:43 AM
Ooops:rolleyes: .... sorry about that! In a hurry to go out!

saghir69
10-25-2004, 11:28 AM
thanks guys :)