2

I'm learning to PHP and now I'm trying to test a simple basic authentication example from here, the code is below:

<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Text to send if user hits Cancel button';
    exit;
} else {
    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
    echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?>

But when I enter username and password, and click Login, auth popup just popping up again with clear fields, every attempt. And only if I click Cancel, it displays echo text from first if statement. How do I make it to work properly (displaying username and pass after Login)? I'm using free biz.nf host and Chrome browser if that matters. Thanks.

1valdis
  • 1,009
  • 1
  • 15
  • 27

0 Answers0