Forum Moderators: coopster

Message Too Old, No Replies

Redirect To page on login failure (Using header:Authenticate)

         

ayazakn

9:56 am on Aug 29, 2004 (gmt 0)

10+ Year Member



Hi All, I am new to PHP so may be missing some basic thing.

I am using header WWW-Authenticate for user credentials, and need to redirect to another page on unsucceessful login. The authentication is woking fine if i skip the header ("Location") part. As soon as the header ("Location") line is uncommented, NO RROMPT FOR USER CREDENTIALS, and it is redirected to the url specified in header(location).

Any help would be highly appreciated.

Please see the code below.

//In my page
if (!login()){
Header("Location: some_absolute_URL");
} else {
// REST OF THE CODE
}

//From library (using include)
function login(){
if (!isset($_SERVER['PHP_AUTH_USER'])){
Header("WWW-Authenticate: Basic realm=\"REALM\"");
Header("HTTP/1.0 401 Unauthorized");
return(FALSE);
} else {
//Database Connection and result on query
if($fetchedRow){
if (($_SERVER['PHP_AUTH_USER']==*db.USERNAME*) && ($_SERVER['PHP_AUTH_PW']==*db.PASSWORD*)){
return(TRUE);
} else {
return(FALSE);
}
}
else{
return(FALSE);
}
}
}

killroy

10:03 am on Aug 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why not first redirect and then authenticate at the destination?

SN

ayazakn

11:25 am on Aug 29, 2004 (gmt 0)

10+ Year Member



Thanks for the quick reply.

I need to redirect only if user has entered invalid username/password, otherwisw, normal code will be executed.

Cannot use meta tag redirect by returning the html, because of requirement.