note 51259 deleted from features.http-auth by cmb

From: Date: Sun, 13 Oct 2019 08:19:14 +0000
Subject: note 51259 deleted from features.http-auth by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212642@lists.php.net to get a copy of this message
Note Submitter: sl at netcentrex dot net ---- This forces an instant re-authentication: // Force a logout. function imt_logout() { global $_SESSION; global $HTTP_SERVER_VARS; global $PHP_SELF; // We mark the session as requiring a re-auth $_SESSION['reauth-in-progress'] = 1; // This forces the authentication cache clearing header("WWW-Authenticate: Basic realm=\"My Realm\""); header("HTTP/1.0 401 Unauthorized"); // In case of the user clicks "cancel" in the dialog box print '<a href="http://'.$HTTP_SERVER_VARS['HTTP_HOST'].$PHP_SELF.'">click me</a>'; exit(); } // Check login function imt_login() { global $_SERVER; global $_SESSION; global $REGISTERED_USERS; // the valid_user checks the user/password (very primitive test in this example) if (!valid_user($_SERVER['PHP_AUTH_USER'], $REGISTERED_USERS)) { session_destroy(); header("WWW-Authenticate: Basic realm=\"My Realm\""); header("HTTP/1.0 401 Unauthorized"); exit(); } // OK, the user is authenticated $_SESSION['user'] = $_SERVER['PHP_AUTH_USER']; } Assuming that your page.php?action=logout forces a reauth on the same page, start your page with: session_start() if ($_REQUEST["action"] == "logout") { if (isset($_SESSION['reauth-in-progress'])) { session_destroy(); header("Location: http://".$HTTP_SERVER_VARS['HTTP_HOST'].$PHP_SELF); } else imt_logout(); } imt_login();

« previous php.notes (#212642) next »