WWW-Authenticate example
// (Source: http://codedump.jonasjohn.de/ - Public domain)
1 2 <?php 3 4 $login_successful = false; 5 6 // check user & pwd: 7 if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){ 8 9 $usr = $_SERVER['PHP_AUTH_USER']; 10 $pwd = $_SERVER['PHP_AUTH_PW']; 11 12 if ($usr == 'jonas' && $pwd == 'secret'){ 13 $login_successful = true; 14 } 15 } 16 17 // login ok? 18 if (!$login_successful){ 19 20 // send 401 headers: 21 // realm="something" will be shown in the login box 22 header('WWW-Authenticate: Basic realm="Secret page"'); 23 header('HTTP/1.0 401 Unauthorized'); 24 print "Login failed!\n"; 25 26 } 27 else { 28 // show secret page: 29 print 'you reached the secret page!'; 30 } 31 ?>