Authenticate username and password to individual PHP pages using 401 header
Want to be able to have users authenticate to individual
pages, or even have a directory full of pages and only
certain pages have authentication? It's as simple as saving
the below code into something like "auth.php" and including
it into the top of your page you want authenticated protection
for.
Just edit the array in the below code with the usernames and
passwords for each of your users. Then on the page you want to
protect, put this line above any other code.
include('auth.php');
Or whatever filename you chose for the below code.
Please note that this works in PHP 5.0.1 and higher.
Click here to see it in action.
See source code below for username and password.
echo '';
highlight_file('authenticate_401.phps');
echo ' ';
?>
|