Jump to content

php http authentication


jandrews3

Recommended Posts

The following code continues to ask for authentication even if I enter the right username (foo) and password (bar). What am I doing wrong?

<?
if ( $auth != 1 ) {		//if the user isn't authenticated

    header( "WWW-Authenticate: Basic realm=\"Authorization Required!\"" ); //this makes the browser generate a login box
    header( "HTTP/1.0 401 Unauthorized" ); //this tells the browser that further viewing is not permitted
    echo 'Authorization Required!'; //and this gets echoed if the user doesn't enter the correct username/password pair
    exit; //this makes the script exit, and the user session ends. No script for you!
}


$auth = 0; // Assume user is not authenticated
if (($PHP_AUTH_USER == "foo" ) && ($PHP_AUTH_PW == "bar" )) $auth = 1; //If all is well, consider the user authenticated


?>
<html>
<head>

	<meta http-equiv="content-type" content="text/html; charset=utf-8">
	<title>test</title>

</head>
<body>
<p>You must have entered the right password.</p>
</body>
</html>

 

 

Link to comment
https://forums.phpfreaks.com/topic/95803-php-http-authentication/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.