
January 30th, 2003, 10:16 AM
|
|
Junior Member
|
|
Join Date: Jan 2003
Location: Acton, California
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
PHP Authentication with Logout
I have a successful PHP authentication scheme and I want to add a logout feature. I added some sample code from a DevArticle and it causes a repeated user/password prompted. Here's the code:
PHP Code:
<?php
$login_attemps = 0;
function authenticate()
{
global $login_attemps;
$login_attemps += 1;
if( $login_attemps > 4 )
{
login_failed();
exit;
}
header('WWW-Authenticate: Basic realm="AVPPNG"');
header('HTTP/1.0 401 Unauthorized');
login_failed();
exit;
}
// The next two lines are the new code that cause a repeated user/pw prompt
if ($_REQUEST['logout'] == true)
{ authenticate(); }
if(!isset($PHP_AUTH_USER) )
{ authenticate(); }
else
{
$q = sprintf( "SELECT * FROM member_registration
WHERE email='%s' AND password='%s'",
trim($PHP_AUTH_USER), crypt(trim($PHP_AUTH_PW),"Xq"));
$result = mysql_query($q);
if (mysql_num_rows($result) == 0)
{
authenticate();
}
else
{
$email = $PHP_AUTH_USER;
$user_profile = mysql_fetch_array($result, MYSQL_ASSOC);
}
}
?>
|