HTTP authentication logout via PHP


Question

What is the correct way to log out of HTTP authentication protected folder?

There are workarounds that can achieve this, but they are potentially dangerous because they can be buggy or don't work in certain situations / browsers. That is why I am looking for correct and clean solution.

1
149
5/1/2009 7:04:57 AM

Accepted Answer

Mu. No correct way exists, not even one that's consistent across browsers.

This is a problem that comes from the HTTP specification (section 15.6):

Existing HTTP clients and user agents typically retain authentication information indefinitely. HTTP/1.1. does not provide a method for a server to direct clients to discard these cached credentials.

On the other hand, section 10.4.2 says:

If the request already included Authorization credentials, then the 401 response indicates that authorization has been refused for those credentials. If the 401 response contains the same challenge as the prior response, and the user agent has already attempted authentication at least once, then the user SHOULD be presented the entity that was given in the response, since that entity might include relevant diagnostic information.

In other words, you may be able to show the login box again (as @Karsten says), but the browser doesn't have to honor your request - so don't depend on this (mis)feature too much.

102
5/23/2017 12:10:30 PM

Method that works nicely in Safari. Also works in Firefox and Opera, but with a warning.

Location: http://logout@yourserver.example.com/

This tells browser to open URL with new username, overriding previous one.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon