2

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

5
  • Is your server set up to serve https:// URLs from the same document root? If you try to access a normal helloworld.php with just an echo() in it through SSL, does that work? Commented Jul 15, 2010 at 11:55
  • Yes, my server have the SSL enabled and the same URL works with http and https both. Commented Jul 15, 2010 at 11:57
  • 2
    Try close browser, open it again and open https page. Commented Jul 15, 2010 at 12:08
  • 1
    @Riateche it works. Thanks..!! as its just a browser issue what should I do now. Should I close this question or let it be open so others can get help? Commented Jul 15, 2010 at 12:16
  • Wow, it's been 8 years and nobody answered you? Sorry! Definitely close it as off topic because then it can no longer be reproduced. Commented Sep 12, 2018 at 18:53

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.