note 9907 deleted from function.header by jimw

From: Date: Wed, 31 Oct 2001 21:45:31 +0000
Subject: note 9907 deleted from function.header by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-19753@lists.php.net to get a copy of this message
I think the example from joe@aigraphics.com is slightly wrong, although it helped me a lot. (Thanks!) The parens in the last if statement are misplaced and I don't see why you're setting $PHP_AUTH_USER et al to an empty value. (There is an "exit" a few lines below anyway.) And the browser should also get a 401 error when the password was wrong, so that the user can retry the input. My script (which works fine for me) looks like this: &lt;?php ob_start() ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html><head><title>some title</title> </head><body>&lt;?php # ... some other code ... if(!( $PHP_AUTH_USER == 'luser' and $PHP_AUTH_PW == 'secret' )) { ob_end_clean(); Header('WWW-Authenticate: Basic realm="test"'); Header('HTTP/1.0 401'); ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html><head> <title>Authentication failed</title> </head><body> <h1>Authentication failed</h1> <p>Your user and/or password input was wrong.</p> <p>To try again, please hit the "reload" button on your browser or <a href="?&lt;?php echo htmlspecialchars($HTTP_SERVER_VARS['QUERY_STRING'])?>">click here</a>. &lt;?php require( 'footer.php' ); echo '</body></html>'; exit; } ob_end_flush(); # ... some more other code ... require( 'footer.php' ); ?></body></html>

« previous php.notes (#19753) next »