Mega Code Archive

 
Categories / Php / MySQL Database
 

User authentication with php3 and msql

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