Learning PHP and MySQL

Example 13-4 Using HTTP authentication with a PHP script

<?php
if  (!isset($_SERVER['PHP_AUTH_USER'])  ||  !isset($_SERVER['PHP_AUTH_PW']))  {
header
('WWW-Authenticate:  Basic  realm="Member  Area"');
header("HTTP/1.0  401  Unauthorized");
echo  
"Please  login  with  a  valid  username  and  password.";
exit;
}  else  {
echo  "You  entered  a  username  of:  ".$_SERVER['PHP_AUTH_USER']."  ";
echo  
"and  a  password  of:  ".$_SERVER['PHP_AUTH_PW'].".";
}
?>

Posted by on 09/25 at 11:26 AM

Next entry: Example 13-5 Checking the values returned from the authentication prompt

Previous entry: Example 13-3 Destroying a cookie by expiring it in the recent past

<< Back to main