note 15724 added to features.http-auth

From: Date: Thu, 27 Sep 2001 23:48:07 +0000
Subject: note 15724 added to features.http-auth
Groups: php.notes 
Request: Send a blank email to php-notes+get-18396@lists.php.net to get a copy of this message
LOGOUT SOLUTION WITH COOKIES !!!!! Generic example: <?php $username = $PHP_AUTH_USER; $password = $PHP_AUTH_PW; cfunction authenticate() { Header("WWW-authenticate: Basic realm=\"Restrict (".strftime("%r",time()).")\""); Header("HTTP/1.0 401 Unauthorized"); echo "You must enter a valid login ID and password to access this resource\n"; exit; } if($logout==1) { setcookie("login","off"); $PHP_SELF = str_replace("logout=1","",$PHP_SELF); header("Location: $PHP_SELF"); exit(); } if(!isset($username) && !isset($password) || $login=="off") { setcookie("login","on"); authenticate(); } else { /* Authtentication code here */ if(!$auth) { authenticate(); } else setcookie("login","on"); } ?> Hi <?=$PHP_AUTH_USER?> you are logged in :-) <a href="<?=$PHP_SELF?>?logout=1">Click here to logout</a> --------------------------------------------------------------- IMAP or POP3 Authentication EXAMPLE <?php $username = $PHP_AUTH_USER; $password = $PHP_AUTH_PW; // $dsn = "{localhost/imap:143}"; $dsn = "{localhost/pop:110}"; cfunction authenticate() { Header("WWW-authenticate: Basic realm=\"Restrict (".strftime("%r",time()).")\""); Header("HTTP/1.0 401 Unauthorized"); echo "You must enter a valid login ID and password to access this resource\n"; exit; } if($logout==1) { setcookie("login","off"); $PHP_SELF = str_replace("logout=1","",$PHP_SELF); header("Location: $PHP_SELF"); exit(); } if(!isset($username) && !isset($password) || $login=="off") { setcookie("login","on"); authenticate(); } else { $imap = @imap_open($dsn, $username, $password, OP_HALFOPEN); if(!$imap) { authenticate(); } else setcookie("login","on"); } @imap_close($imap); ?> Hi <?=$PHP_AUTH_USER?> you are logged in :-) <a href="<?=$PHP_SELF?>?logout=1">Click here to logout</a> -- http://www.php.net/manual/en/features.http-auth.php http://master.php.net/manage/user-notes.php?action=edit+15724 http://master.php.net/manage/user-notes.php?action=delete+15724 http://master.php.net/manage/user-notes.php?action=reject+15724

« previous php.notes (#18396) next »