note 54330 deleted from features.http-auth by cmb
| From: | cmb@php.net | Date: | Sun, 13 Oct 2019 08:17:57 +0000 |
| Subject: | note 54330 deleted from features.http-auth by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212639@lists.php.net to get a copy of this message | ||
Note Submitter: me at lalit dot org
----
A very simple HTTP Authentication script that solves the logout problem. I wasted a lot of time
figuring out a way to logout. This one works perfectly fine.
<?php
function auth_user() {
$realm = mt_rand( 1, 1000000000 );
header('WWW-Authenticate: Basic realm="Realm ID='.$realm.']"');
header('HTTP/1.0 401 Unauthorized');
die("Unauthorized access forbidden!");
}
if (!isset($_SERVER['PHP_AUTH_USER'])) {
auth_user();
} else if (!isset($_SERVER['PHP_AUTH_USER'])) {
auth_user();
} else if ($_SERVER['PHP_AUTH_USER'] != $auser || $_SERVER['PHP_AUTH_PW'] !=
$apass) {
auth_user();
} else if (isset($_GET['action']) && $_GET['action'] ==
"logout") {
auth_user();
}
// Normal Page Code Here
?>
Hope this helps,
Lalit