note 61922 added to features.http-auth
| From: | djreficul at yahoo dot com | Date: | Wed, 15 Feb 2006 10:14:18 +0000 |
| Subject: | note 61922 added to features.http-auth | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103755@lists.php.net to get a copy of this message | ||
Well, I think it's easy to make authentification works correctly. I use a session var to force
authentication everytime a user visit the logging area.
<?php
if (!isset ($_SESSION['firstauthenticate'])) {
session_start();
}
function authenticate() {
header('WWW-Authenticate: Basic realm="Sistema autentificación
UnoAutoSur"');
header('HTTP/1_0 401 Unauthorized');
// header("Status: 401 Access Denied");
echo "Unauthorized\n";
exit;
}
if (!isset($_SERVER['PHP_AUTH_USER']) || strcmp
($_SERVER['PHP_AUTH_USER'],$user)!=0 ||
!isset ($_SERVER['PHP_AUTH_PW']) || strcmp($_SERVER['PHP_AUTH_PW'],$pass)!=0
|| !isset ($_SESSION['firstauthenticate']) || !$_SESSION['firstauthenticate']) {
$_SESSION['firstauthenticate']=true;
authenticate();
} else {
//I destroy the session var now
session_unset();
//Your code below
}
?>
----
Server IP: 64.246.30.37
Probable Submitter: 80.34.95.66
----
Manual Page -- http://www.php.net/manual/en/features.http-auth.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61922
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61922&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61922&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61922&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61922&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61922&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61922&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61922&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61922&report=yes
Search -- http://master.php.net/manage/user-notes.php