/ Published in: PHP
URL: http://www.thatgrafix.com
I thought I would share this simple username password PHP auth script. It leans on HTTP to secure a page.. not bulletproof but quick and painless.
Expand |
Embed | Plain Text
<?php // input user/pass below $username = "INSERT YOUR DESIRED USERNAME HERE"; $password = "INSERT YOUR DESIRED PASSWORD HERE"; // password protect via http $_SERVER['PHP_AUTH_USER'] == $username && $_SERVER['PHP_AUTH_PW'] == $password)){ }else{ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Page Name</title> </head> <body> <!-- // html --> </body> </html> <?php } ?>
Comments
Subscribe to comments
You need to login to post a comment.

You can also extend this to multiple usernames and passwords by using an associated array.
$users = array("fred" => "fl1ntst0n3", "barney" => "rubbl3");In the IF statement, you feed PHPAUTHUSER to the array as a key. If a value is retrieved, the user is valid and you can check the value against PHPAUTHPW.
Good Call :)