note 15724 deleted from features.http-auth by irc-html

From: Date: Sat, 19 Jan 2002 20:29:32 +0000
Subject: note 15724 deleted from features.http-auth by irc-html
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-25320@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>

« previous php.notes (#25320) next »