简体   繁体   中英

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.

//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. Closing then re-opening the browser with HTTPS solves the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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