简体   繁体   English

PHP:SSL HTTP身份验证?

[英]PHP: SSL HTTP Authentication?

I have a php page in which I have the following code to validate the user using HTTP authentication, this code works fine for http:// url's but when I use the same page with https:// then it didn't ask for username and password. 我有一个php页面,其中有以下代码使用HTTP身份验证来验证用户,此代码适用于http:// url,但是当我将同一页面与https://一起使用时,它并没有要求输入用户名和密码。

//authentication settings
define('USERNAME', 'prashant');
define('PASSWORD', 'password');

//Validating
if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="Authentication required"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Unauthorized access';
    exit;
}else{
    if($_SERVER['PHP_AUTH_USER'] != USERNAME && $_SERVER['PHP_AUTH_PW'] != PASSWORD){
        header('WWW-Authenticate: Basic realm="Authentication required"');
        header('HTTP/1.0 401 Unauthorized');
        echo 'Unauthorized access';
        exit;
    }
}

What's the problem and how I can resolve this? 有什么问题,我该如何解决?

Thanks 谢谢

What's the problem and how I can resolve this? 有什么问题,我该如何解决?

As the comments on this question already addressed, it was caused by browser caching the HTTP authentication details for your domain. 鉴于此问题的评论已经解决,这是由浏览器为您的域缓存HTTP身份验证详细信息引起的。 Closing then re-opening the browser with HTTPS solves the problem. 关闭然后重新打开使用HTTPS的浏览器即可解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM