here is my auth function. you can easily copy this into the top of your script if you wish:
function auth($user = "admin", $pass = "admin123", $msg = "Admin Area") {
// this will return TRUE(1) if user matches password and username
// and will return FALSE(0) if user does not match
// test by: if ( !auth($user, $pass, $msg) ) { echo "access denied";exit; }
global $PHP_AUTH_USER,$PHP_AUTH_PW; // needed.
if ( !isset($PHP_AUTH_USER) ) {
header("WWW-Authenticate: Basic realm=".$msg."");
header ('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
return 0;
}
else if ( isset($PHP_AUTH_USER) ) {
if ( ($PHP_AUTH_USER != $user) || ($PHP_AUTH_PW != $pass) ) {
header("WWW-Authenticate: Basic realm=".$msg."");
header ('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
return 0;
} else {
return 1;
}
}
}
hope this could help,
kyle