note 40331 added to features.http-auth

From: Date: Sun, 29 Feb 2004 05:07:49 +0000
Subject: note 40331 added to features.http-auth
Groups: php.notes 
Request: Send a blank email to php-notes+get-65983@lists.php.net to get a copy of this message
I could not get any of these ways of authenticating to a database to work for me so here is a script that I wrote from scratch that authenticates to a sql database and then does something based on that. <?php $username = $_SERVER['PHP_AUTH_USER']; $password = $_SERVER['PHP_AUTH_PW']; if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="My Realm"'); header('HTTP/1.0 401 Unauthorized'); echo 'Text to send if user hits Cancel button'; exit; } else { $link = mysql_connect('localhost','test','test'); mysql_select_db('users'); $query = "select username, password from users where username = '$username' and password = '$password'"; $result = mysql_query($query); if (($value = mysql_fetch_row($result)) && ($value[0] == $username) && ($value[1] == $password)) { echo "You are authenticated"; } else { echo "Your username or password is incorrect"; } echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>"; echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>"; } mysql_close($link); ?> ---- Manual Page -- http://www.php.net/manual/en/features.http-auth.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40331 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40331&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40331&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#65983) next »