note 44017 deleted from features.http-auth by tomsommer
| From: | tomsommer@php.net | Date: | Mon, 12 Jul 2004 19:56:31 +0000 |
| Subject: | note 44017 deleted from features.http-auth by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73120@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster@tdupage.com
----
After thinking about how to add good logout functionality with basic auth, i decided to try using
cookies. Presto:
<!-- index.php -->
<? header('Set-Cookie: authuser=0'); ?>
<a href="admin.php">Login</a>
<!-- END index.php -->
<!-- admin.php -->
<?
function authUser() {
header('Set-Cookie: authuser=1');
header('WWW-Authenticate: Basic realm="The Realm"');
header('HTTP/1.0 401 Unauthorized');
echo "Error: Invalid Login Information<br><br><a
href=\"index.php\">Back</a>";
exit;
}
if ($_COOKIE['authuser'] == 0) authUser();
if ($_SERVER['PHP_AUTH_USER'] != 'admin') authUser();
if ($_SERVER['PHP_AUTH_PW'] != 'pass') authUser();
//They must be logged in
echo "Your logged in!<br>";
echo "<a href=\"index.php\">Logout</a>";
?>
<!-- END admin.php -->
I welcome all comments!