Wednesday, April 05, 2006

Login - PHP

Login:

if (!isset($_SERVER['PHP_AUTH_USER'])) {
header("WWW-Authenticate: Basic realm=\"Private Area\"");
header("HTTP/1.0 401 Unauthorized");
print
"Sorry - you need valid credentials!\n";
exit;
} else {
if ((
$_SERVER['PHP_AUTH_USER'] == 'user') && ($_SERVER['PHP_AUTH_PW'] == 'pass')) {
print
"Welcome to the private area!";
} else {
header("WWW-Authenticate: Basic realm=\"Private Area\"");
header("HTTP/1.0 401 Unauthorized");
print
"Sorry - you need valid credentials!\n";
exit;
}
}