php authentication help please

Soldato
Joined
6 Jun 2006
Posts
6,012
Location
Kent
So, I've been trying several ways of authentication for a section of my site, the htaccess/passwd route doesn't seem to work though. So, I went out and found a php script, the login box pops up ok, I enter the right user/pass but then it just loops, any ideas please?

This is the code. :)

Code:
<?
//part 1
if (!isset($PHP_AUTH_USER)) 
{ 
    header("WWW-Authenticate: Basic realm=\"Login\""); 
    Header("HTTP/1.0 401 Unauthorized"); 
    exit; 
}     

//part 2
else if(($PHP_AUTH_USER=="user") && ($PHP_AUTH_PW=="password")) 
{ 
   echo "You got in...";
     
} 

//part 3
else  
{ 
   echo "<html><body bgcolor=ffffcc>Failed, please try again."; 
   //fail try again
} 
?>

Any other methods of securing a directory are very welcome, and thanks in advance. :)
 
Your script appears to be relying on register_globals being turned on, which is bad practice. You should replace all the $PHP_AUTH_* variables with $_SERVER['PHP_AUTH_*'] and try again :)

Cool, thanks. I shall try that in a bit. :)
 
Back
Top Bottom