Thursday, 4 June 2015

PHP: User-authentication with php3 and msql

<?php
if(!($PHP_AUTH_USER))
{
Header("WWW-authenticate: basic realm=\"restricted area\"");
Header( "HTTP/1.0 401 Unauthorized");
echo "failed\n";
?>
<meta http-equiv="refresh" content="0;url=failed.php3">
<?php
exit;
}
else
{
msql_connect("localhost");
$user_id=strtolower($PHP_AUTH_USER);
$password=$PHP_AUTH_PW;
$Selstr="select * from user where   
user='$user_id' and password='$password'";
$Result=msql("test",$Selstr);
if(!msql_num_rows($Result))
{
Header( "WWW-authenticate: basic realm=\"restricted area\"");
Header( "HTTP/1.0 401 Unauthorized");
exit;
}
?>
<meta http-equiv="refresh" content="0;url=welcome.php3">
<?php
}
?>

0 comments:

Post a Comment