jad9321
06-26-2006, 04:36 PM
Hello,
How do you password protect a PHP page?
Thanks in advance,
Joe
djr33
06-26-2006, 04:42 PM
Here's the EASY way, but there are more complex ways.
A "get" variable is one in the address bar... like index.php?var=value, where var is the name of the variable and value is the value of that variable.
(note that it can be var1=value&var2=value2&.... as well)
Once you've got that done, it's just a matter of adding this to the top of a page, assuming index.php?password=secret:
<?php
if ($_GET['password'] != "secret") die('No input file selected.');
?>
that's really it. The die function outputs a string, in this case the same exact error you would get if the page didn't exist.... but in this case, it's a VERY nice trick because someone trying to find your secret page wouldn't even know it exists unless they knew the password and where to look... otherwise it would appear to not exist because of the "No input file selected." thing.
Now... get values can also come from forms (just set the form's method="get" and the name of each field will be the variable name, the value the value of that variable)
You can use POST variables... much like get, but behind the scenes, and more secure, probably better for passwords... (method="post" & $_POST['var'])
And you can use cookies, and sessions, and likely even databases.
It all depends... it's a very broad question, but this should explain the basics.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.