User Authentication With Global variables Off

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
freebsd_dude
Forum Newbie
Posts: 1
Joined: Sat Nov 16, 2002 10:09 pm

User Authentication With Global variables Off

Post by freebsd_dude »

Hello all,
I need help in setting up a Database-Driven Authentication using
if (!isset($PHP_AUTH_USER)) {



header('WWW-Authenticate: Basic realm="My Private Stuff"');

header('HTTP/1.0 401 Unauthorized');

echo 'Authorization Required.';

exit;



} else {



$connection = mysql_connect("localhost", "BOZO", "OHPLEASE")

or die ("Couldn't connect to server.");



$db = mysql_select_db("COOLNESS", $connection)

or die ("Couldn't select database.");


$sql = "SELECT id
FROM data

WHERE username='$PHP_AUTH_USER' and password='$PHP_AUTH_PW'";



$result = mysql_query($sql)

or die("Couldn't execute query.");



$num = mysql_numrows($result);



if ($num == 1) {



echo "<P>You are valid!<br>";

echo "Your username is $PHP_AUTH_USER<br>";

echo "Your password is $PHP_AUTH_PW</p>";



} else if ($num == 0) {



echo "You are not authorized!";



}



}



?>
This did work before I installed the new php with Global variables Off
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Post Reply