Click to See Complete Forum and Search --> : Authentication problem


Anon
04-19-2002, 07:55 PM
Hi !

I have installed PHP as a module, but I still
have problems with authentication.
I use the following code :

header("WWW-Authenticate: Basic realm=\"My Realm\"");
header("HTTP/1.0 401 Unauthorized");

The authentication dialog is showed.
I enter user and passwd and submits.
The dialog is still left but with
the password field empty.
I press the OK button again now the user
field is empty. I press OK button again
and now the dialog disappears.

It would be terrific if someone can help me !

Regards
Stefan

mligor
04-22-2002, 09:16 AM
that is normal...

you have to check is username and password is Ok, and then DON'T send header...

something like (original example from php documentation):

<?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 "<p>Hello $PHP_AUTH_USER.</p>";
echo "<p>You entered $PHP_AUTH_PW as your password.</p>";
}
?>


or something like:

if ($PHP_AUTH_USER != "my_user_name" && $PHP_AUTH_PW == "my_password")
{
header("WWW-Authenticate: Basic realm=\"My Realm\"");
header("HTTP/1.0 401 Unauthorized");
echo "sorry, no permitions";
exit; // realy important
}

... your code


IGOR