开发者

http authorisation dialogue box

I'm new to this and need help.

I want to set up an http authentication on my site and have used the following code:

<?php 


if (isset($_SERVER['PHP_AUTH_USER']) &&
    isset($_S开发者_StackOverflow中文版ERVER['PHP_AUTH_PW']))
{
    echo "Welcome User: " . $_SERVER['PHP_AUTH_USER'] .
        " Password: " .     $_SERVER['PHP_AUTH_PW'];
}
else
{
    header('WWW-Authenticate: Basic realm="Restricted Section"');
    header('HTTP/1.0 401 Unauthorized');
    die("Please enter your username and password");
}
?>

When I run the script I get, "Please enter your username and password."

Obviously the 'die' code has run but I don't understand why.

Can anyone help?

'H'


Your 'ide' says the page your looking is authentication required one !

  header('WWW-Authenticate: Basic realm="Restricted Section"');

That is why http authorisation dialogue box appears..


I think that the answer is in here: How to fix "Headers already sent" error in PHP

Though you did not state you are getting the error, you will land directly on the "die" (as if you clicked "cancel") if anything is printed before the header to output.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜