PHP GAE Basic Authentication

if (isset($_SERVER['HTTP_AUTHORIZATION'])) { $nobasic = substr($_SERVER['HTTP_AUTHORIZATION'],6); // removing 'Basic ' from the string $decoded = base64_decode($nobasic); // decoding string with user:password list($client_user, $client_pass) = explode(':',$decoded); if ($client_user == "user" && $client_pass == "password") { // Successfully authenticated } else { // Authentication failed, username or password are wrong header('WWW-Authenticate: Basic realm="site"'); header('HTTP/1.0 401 Unauthorized'); echo "Wrong credentials :-("; exit; } } else { // Not authenticated as there is no appropriate header in HTTP request header('WWW-Authenticate: Basic realm="site"'); header('HTTP/1.0 401 Unauthorized'); echo "Wrong credentials :-("; exit; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.