Re: Login Help
| From: | Marcelo Gulin | Date: | Tue, 02 Jan 2001 20:04:11 +0000 |
| Subject: | Re: Login Help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-32322@lists.php.net to get a copy of this message | ||
Hi Tim!
Try this code...
<?php
if( !isset( $PHP_AUTH_USER ) ) {
Header( "WWW-authenticate: basic realm='Test Authentication
System'");
Header( "HTTP/1.0 401 Unauthorized");
echo "Server message: You must enter a valid login ID and
password to access this resource\n";
exit;
} else {
$opendb = mysql_pconnect("localhost","httpd") or die( "Unable to
access database" );
$selectdb = mysql_select_db("my_users") or die( "Unable to select
database" ) ;
$query = "SELECT * FROM users WHERE username = '" . $PHP_AUTH_USER
."'" ;
$result = mysql_query($query);
if(mysql_num_rows($result)) {
$rec = mysql_fetch_array($result);
if($rec["password"] == $PHP_AUTH_PW ) {
print "Welcome " . $PHP_AUTH_USER . "!" ;
} else {
echo "Access denied!<br>\n";
exit;
}
} else {
echo "Access denied.<br>\n";
exit;
}
}
?>
hope it helps you
regards
Marcelo Gulin
Media IT Group escribió:
>
> Can someone please help me, I need a script that will verify a login name and password with
> that in a mysql database, and then grant access.
>
> Thanks
> Tim