Authentication with multpile "zones"
| From: | Adriano Manocchia | Date: | Tue, 29 Aug 2000 15:53:01 +0000 |
| Subject: | Authentication with multpile "zones" | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-14156@lists.php.net to get a copy of this message | ||
I'm trying to implement authentication on a website using PHP3 and MySQL. I have it working fine with one set of login/passes, but I would like to have certain files that only some users can access. I have separate db's and cookies, but as far as I can tell, as long as you've entered a successful login/pass, and $PHP_AUTH_USER exists, you can get in anywhere with the following implementation.
login.php3:
<?PHP
if(!($PHP_AUTH_USER)):
Header("WWW-authenticate: basic realm=<whatever>");
Header("HTTP/1.0 401 Unauthorized");
echo "<meta http-equiv=\"refresh\" content=\"0;url=failed.html\">";
exit;
else:
$conn=mysql_connect("localhost","<user>","<pass>");
mysql_select_db("<db>",$conn);
if (!conn) {echo "An error occurred in connection.\n";exit;}
$user_id=strtoupper($PHP_AUTH_USER);
$password=$PHP_AUTH_PW;
$result=mysql_query("SELECT * FROM <table> WHERE email='$user_id' and password='$password'",$conn);
if (!$result): echo "An error occurred. Please try again."; exit;
endif;
$num=mysql_NumRows($result);
if (mysql_NumRows($result)>0):
SetCookie("<COOKIE1>",$user_id,time()+1);
SetCookie("<COOKIE1>",$user_id,time()+1,"/",".server.name");
echo "<meta http-equiv=\"refresh\" content=\"0;
url=home.php3\">";
exit;
else:
Header("WWW-authenticate: basic realm=<whatever>");
Header("HTTP/1.0 401 Unauthorized");
echo "<meta http-equiv=\"refresh\" content=\"0;url=failed.html\">";
exit;
endif;
endif;
?>
header for protected files:
<?PHP
if(!($PHP_AUTH_USER)):
echo "<meta http-equiv=\"refresh\"
content=\"0;url=secretpage.php3\">";
endif;
?>
Is there some way to do what I need that I'm missing? Thanks.
Age
--
------------------------------------------------------------
Adriano "Age" Manocchia am33@cornell.edu
Cornell University AIM: BigRedWhat
http://www.hockey.cornell.edu/age
------------------------------------------------------------
"The capacity to blunder slightly is the real marvel of DNA.
Without this special attribute, we would still be anaerobic
bacteria, and there would be no music." -Lewis Thomas