Post Reply 
Quick password protection with PHP
01-04-2012, 02:41 PM
Post: #1
Quick password protection with PHP
This is a very simple and easy to implement script that will password protect any web page. Insert this code at the top of any web page, and it is protected:
Code:
<?php
$username="user";
$password="password";
if (!$_POST["user"]==$username||!$_POST["pass"]) {
if ($_POST["user"]||$_POST["pass"]) echo "Password incorrect. Try again.";
else echo "This page is password protected.";
?>
<form action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post">
Username: <input type="text" name="user"><br>
Password: <input type="password" name="pass"><br>
<input type="submit" value="Validate">
</form>
<?php } ?>
Simply change the second and third lines to the desired username and password, leaving the quotes in place. For this to work, PHP must be installed on the server, and the page must have an extension of .php, rather than, for instance, .html

Best regards,
D. Strout
I'm a web developer from New England. Please +Rep if I've helped, or if you're just feeling nice Smile
My sites: DStrout.net | U3 Applications | SpamLot
User Tools
Quote this message in a reply


01-07-2012, 08:20 AM
Post: #2
RE: Quick password protection with PHP
the downside to this is that google ranks you site about 1000 lower due to restricted content

Vampire IRC Network
This site is currently being created
User Tools
Quote this message in a reply
01-09-2012, 03:42 AM
Post: #3
RE: Quick password protection with PHP
@tycoon,

lol, it doesn't. dont protect your whole website Smile

Looking for sponsor Wink My blog visitor about 2000/day
User Tools
Quote this message in a reply
01-09-2012, 05:14 AM
Post: #4
RE: Quick password protection with PHP
(01-09-2012 03:42 AM)lanogan Wrote:  @tycoon,

lol, it doesn't. dont protect your whole website Smile

Yes, the idea behind this is that you will be using this on a page not usually visited by most people, possibly not even linked to, but which still needs extra protection.

Best regards,
D. Strout
I'm a web developer from New England. Please +Rep if I've helped, or if you're just feeling nice Smile
My sites: DStrout.net | U3 Applications | SpamLot
User Tools
Quote this message in a reply
Post Reply 


Forum Jump:



User(s) browsing this thread:
1 Guest(s)