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

From: Date: Sat, 19 Jan 2002 20:29:08 +0000
Subject: note 13298 deleted from features.http-auth by irc-html
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-25317@lists.php.net to get a copy of this message
After playing around with all the good advice that was previously posted on this site, I've come up with a small script that works on all instances of user input - that being correct input, no input (hitting the cancel button), or incorrect input. --- <? function no_auth_msg() { global $PHP_SELF; $page = basename($PHP_SELF); echo "<h1>401 Authorization Required</h1>"; echo "This server could not verify that you are authorized to access the document requested. "; echo "Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't "; echo "understand how to supply the credentials required. Please "; echo "<a href=\"http://yourURL/$page\">"; echo "click here</a> to try again."; } function authenticate() { Header("WWW-Authenticate: Basic realm=\"Members Area\", stale=FALSE"); Header("HTTP/1.0 401 Unauthorized"); no_auth_msg(); exit; } if (isset($PHP_AUTH_USER)) { // Verify username and pw include("db_connect.php3"); $sql = "SELECT * FROM users WHERE username=\"$PHP_AUTH_USER\" AND password=\"$PHP_AUTH_PW\""; if (!($result = mysql_db_query("database", $sql))) { die("Unable to access database. Please try again later."); } if (mysql_num_rows($result) > 0) { // User is valid header("Location: member.php3"); exit; } else { // User is not valid authenticate(); } } else { // username is not yet set // Show authentication dialogue authenticate(); } ?>

« previous php.notes (#25317) next »