Nick,

I'm not sure were you are getting the value of $PHP_AUTH_USER from, so you
might want to try this snippet. This causes a dialog box to open and ask for
a username/password.

Also, in your code: you do not need to escape the quotes in the header.

<?
 // Check to see if $PHP_AUTH_USER already contains info
 if (!isset($PHP_AUTH_USER)) {
    // If empty, send header causing dialog box to appear
    header('WWW-Authenticate: Basic realm="Whatever You want to say"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Authorization Required!';
    exit;
 } else if (isset($PHP_AUTH_USER)) {
    if (($PHP_AUTH_USER !="abc") || ($PHP_AUTH_PW !="123")) {
       header('WWW-Authenticate: Basic realm="Whatever You want to say"');
       header('HTTP/1.0 401 Unauthorized');
       echo 'Authorization Required!';
       exit;
  } else {
   // Start echo statement
   echo "hello";
  }
}
?>

----- Original Message -----
From: "Nick Kostirya" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, February 07, 2001 10:27 AM
Subject: [PHP] HTTP Authentication


> Hi, all.
> HTTP Authentication in PHP 4 - Apache don't work!!!
> Help me.
> Best.
> __________________________________________________
> <?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>";
>   }
> ?>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to