Correct code ?? PHP Basic pw athentication with mysql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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!";
 }
}
 ?>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux