note 91328 deleted from features.http-auth by danbrown
| From: | danbrown@php.net | Date: | Mon, 08 Jun 2009 12:43:30 +0000 |
| Subject: | note 91328 deleted from features.http-auth by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156467@lists.php.net to get a copy of this message | ||
Note Submitter: wide_bucs19 at hotmail dot com
----
I got to experimenting with someone else's little bit of code, and I came up with this one. It
seems to work rather sharp for me, not sure on security or anything but maybe it'll help some
other people.
<?php
if($_GET['opipopip'] == 'logout') {
header('WWW-Authenticate: Basic realm="Click \'Ok\' then \'Cancel\'
to Log Out"');
header('HTTP/1.0 401 Unauthorized');
echo 'You have been successfully logged out. Click <a
href="index.php">here</a> to log back in.';
die();
}
if((!isset($_SERVER[PHP_AUTH_USER])) || ($_SERVER[PHP_AUTH_USER] != array('username1',
'username2') && $_SERVER[PHP_AUTH_PW] != 'password')) {
header('WWW-Authenticate: Basic realm="Site Login"');
header('HTTP/1.0 401 Unauthorized');
echo 'You must enter a valid username and password to access this resource. <a
href="index.php">Retry</a>.';
die();
} else {
echo 'You have successfully logged in, <a
href="index.php?opipopip=logout">Logout</a>';
}
?>
Best of luck.