note 44017 added to features.http-auth
| From: | webmaster at tdupage dot com | Date: | Mon, 12 Jul 2004 17:55:09 +0000 |
| Subject: | note 44017 added to features.http-auth | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-73110@lists.php.net to get a copy of this message | ||
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!
----
Manual Page -- http://www.php.net/manual/en/features.http-auth.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44017
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44017&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44017&report=yes
Search -- http://master.php.net/manage/user-notes.php