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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.