note 93255 deleted from features.http-auth by danbrown

From: Date: Mon, 31 Aug 2009 03:53:30 +0000
Subject: note 93255 deleted from features.http-auth by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-160073@lists.php.net to get a copy of this message
Note Submitter: s dot i dot g at gmx dot com ---- <?php // try to mimic cpanel logout style // only diff is usr & pwd field is cleared when re-login // tested with ff2 & ie8 session_start(); $username = "test"; $password = "test"; if(isset($_GET['logout'])) { unset($_SESSION["login"]); echo "You have logout ... "; echo "[<a href='" . $_SERVER['PHP_SELF'] . "'>Login</a>]"; exit; } if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !isset($_SESSION["login"])) { header("WWW-Authenticate: Basic realm=\"Test\""); header("HTTP/1.0 401 Unauthorized"); $_SESSION["login"] = true; echo "You are unauthorized ... "; echo "[<a href='" . $_SERVER['PHP_SELF'] . "'>Login</a>]"; exit; } else { if($_SERVER['PHP_AUTH_USER'] == $username && $_SERVER['PHP_AUTH_PW'] == $password) { echo "You have logged in ... "; echo "[<a href='" . $_SERVER['PHP_SELF'] . "?logout'>Logout</a>]"; } else { unset($_SESSION["login"]); header("Location: " . $_SERVER['PHP_SELF']); } } // content here ?>

« previous php.notes (#160073) next »