Authentication Php

if(!($PHP_AUTH_USER))
{
Header("WWW-authenticate: basic realm=\"restricted area\"");
Header( "HTTP/1.0 401 Unauthorized");
echo "failed\n";
?>

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

}
?>