Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple password field

Status
Not open for further replies.

ayersart

Technical User
Dec 21, 2004
69
US
I am looking for a very simple way to password protect a page. Very simple. I have one box for password (no username needed), and a submit button takes you to the right page if the password is correct, and a different page if it is incorrect. How would I go about this?
 
You'll need either Javascript or some kind of server-side language to do it.

If you want to use Javascript you can post your qustion in the Js forum here: forum216.

If you have a server-side language available to you tell us what it is and we may be able to help further.

On a side note. the method you describe is not very secure, as anybody can just point their browser to the final page without really going through the password form.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I have PHP, it is not a matter of high security, so something simple and basic would be fine. ?
 
with PHP it would simply be a question of redirecting on a valid password:

Code:
<?
if(isset($_POST['mypassword'])){[green]//check whether the field has been submitted [/green]
if($_POST['mypassword']=="codedpassword"){[green]\\check if the field contents match your password and redirect
[/green]
header(Location:some_other_page.html)
}
else{
[green]//if the password doesn't match issue a message[/green]
echo "Wrong Password";
}
}
else{
[green]\\nothing was submitted just display the form[/green]
and whatever other html you want.
echo "<form ...><input type=password name=mypassword...>";
}

?>

Note of caution there can be nothing sent to the browser before issuing the header command otherwise you'll get an error stating that the headers have already been sent. And no redirect will occur. And by nothing i mean nothing, no html, no tags not even white space. So when you do this make sure you encase the rest of your page in the outer else so it doesn't get sent to the browser unless the form has not been submitted.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top