user874457
user874457

Reputation:

http authorisation dialogue box

I'm new to this and need help.

I want to set up an http authentication on my site and have used the following code:

<?php 


if (isset($_SERVER['PHP_AUTH_USER']) &&
    isset($_SERVER['PHP_AUTH_PW']))
{
    echo "Welcome User: " . $_SERVER['PHP_AUTH_USER'] .
        " Password: " .     $_SERVER['PHP_AUTH_PW'];
}
else
{
    header('WWW-Authenticate: Basic realm="Restricted Section"');
    header('HTTP/1.0 401 Unauthorized');
    die("Please enter your username and password");
}
?>

When I run the script I get, "Please enter your username and password."

Obviously the 'die' code has run but I don't understand why.

Can anyone help?

'H'

Upvotes: 0

Views: 266

Answers (2)

Yaniv
Yaniv

Reputation: 1

I think that the answer is in here: How to fix "Headers already sent" error in PHP

Though you did not state you are getting the error, you will land directly on the "die" (as if you clicked "cancel") if anything is printed before the header to output.

Upvotes: 0

nidhin
nidhin

Reputation: 6920

Your 'ide' says the page your looking is authentication required one !

  header('WWW-Authenticate: Basic realm="Restricted Section"');

That is why http authorisation dialogue box appears..

Upvotes: 2

Related Questions