Correct code ?? PHP Basic pw athentication with mysql

From: Date: Mon, 27 Jul 2009 06:07:16 +0000
Subject: Correct code ?? PHP Basic pw athentication with mysql
Groups: php.general 
Request: Send a blank email to php-general+get-295858@lists.php.net to get a copy of this message
I cant seem to get this to work. Any ideas?? And If I have post this to the wrong area.. My sincere apologies! Thank you in advance! Jason <?php if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="My realm"'); header("HTTP/1.0 401 Unauthorized"); echo "Authorization Required."; exit; } else { $cxn = mysql_connect("localhost","root","") or die ("You didnt get this right!"); $db = mysql_select_db("secretdb",$cxn) or die ("Couldn't connect"); $sql = "SELECT id FROM users WHERE username = '$_SERVER[PHP_AUTH_USER]' and 'password' = '$_SERVER[PHP_AUTH_PW]'"; $result = mysql_query($sql) or die ("Couldn't get results."); $num = mysql_numrows($result); if($num == 1) { echo "<P>You are a valid user<BR>"; echo "Your username is: {$_SERVER['PHP_AUTH_USER']}<BR>"; echo "Your password is: {$_SERVER['PHP_AUTH_PW']}<BR>"; } else { echo "You are not authorized!"; } } ?>

« previous php.general (#295858) next »