Skip to content
PHP Logo

What are the potential issues with logging out of a PHP website using WWW-Authentification?

One potential issue with logging out of a PHP website using WWW-Authentication is that the browser may cache the credentials and automatically re-authenticate the user, making it difficult to completely log out. To solve this issue, you can send a 401 Unauthorized header along with clearing any stored credentials in the browser.

php
<?php
// Clear any stored credentials in the browser
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="My Website"');
?>