Reputation: 484
I've found following code
<?php
$_SERVER['PHP_AUTH_USER'] = 'Me';
if (empty($_SERVER['PHP_AUTH_PW'])) {
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>";
}
?>
according to the above code, it prompts a username and password empty fields. I'm trying to find a way to force a username to always show up, but keeping password for the user to type it. So is there a way to always lock the username ? Please help.
Upvotes: 2
Views: 3501
Reputation: 67
This will never happen because HTTP is a stateless protocol by definition.
You can, however, include the credentials within the request URI:
https://username:[email protected]/path
Upvotes: 0