note 51259 added to features.http-auth

From: Date: Thu, 24 Mar 2005 22:16:54 +0000
Subject: note 51259 added to features.http-auth
Groups: php.notes 
Request: Send a blank email to php-notes+get-86907@lists.php.net to get a copy of this message
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(); ---- Manual Page -- http://www.php.net/manual/en/features.http-auth.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51259 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51259&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51259&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51259&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51259&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51259&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51259&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86907) next »