Page 1 of 1

HTTP Authentication

Posted: Fri Jan 17, 2003 3:57 am
by desmondlk
>>I am currently using PHP version 4.0.4.
>>I decided to using browser HTP authentication.

Code: Select all

<?php
  if(!isset($PHP_AUTH_USER)) {
    Header("WWW-Authenticate: Basic realm="My Realm"");
    Header("HTTP/1.0 401 Unauthorized");
    echo "Text to send if user hits Cancel button\n";
    exit;
  } else {
    echo "Hello $PHP_AUTH_USER.<P>";
    echo "You entered $PHP_AUTH_PW as your password.<P>";
  }
?>
>>I create a file named authen.php with the code above.
>>And I try to execute the file, it display internal server error.

>>Do I need to create .htaccess and .htpasswd files?
>>How both should be enclosed with?
>>Or other configuration in the server?

>>please help. Thanks in advance.

Posted: Fri Jan 17, 2003 4:01 am
by twigletmac
Which web server and OS are you using?

Mac

Posted: Sun Jan 19, 2003 8:33 pm
by desmondlk
Dear twigletmac,

>>I am using XP Pro and Apache server.