开发者

Why is it that when I use HTTP authentication with PHP it doesn't close until I press "Cancel"?

In PHP I'm trying to create a basic HTTP authentication login (the one that pops up). Its my understanding this is done through a header, and this is my header:

header("WWW-Authenticate: Basic realm='Secure Area'");

After that, I check to see if the input username or password is incorrect, and if it is I execute one function or a开发者_如何学Pythonnother:

if ($_SERVER["PHP_AUTH_USER"] != $username || $_SERVER["PHP_AUTH_PW"] != $password)
{
    quit();
}
else
{
    main();
}

However, when I test my code, and I enter the correct username and password and press "Log In" the login popup box just opens again, after the second time opening, I can press "Cancel" and it takes me to the result of the main function, but if I just keep pressing "Log In" it just keeps popping up.

Other than that, it works normally. If I press "Cancel" without correctly entering the username or password first it will quit. However, I need to resolve the problem of this seemingly 'endless login'.

How can I fix it?


I guess you are resending the authenticate header even after the user is authenticated. Move the header() call into the if block, instead of quit().

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜