Jump to content

user authentication


sonners

Recommended Posts

Ok when I say I am a novice - I really do mean I am clueless.
Q.
I have a folder with access restricted using .htpassd.
The user types in username and password into the window box.
They go to a shtml page.
How do I get the username that they type in to appear on the shtml page as "Hello, username"
I have tried all these scripts and none work:
<?php
$usera = $_SERVER["PHP_AUTH_USER"];
echo 'Current user is'.$usera.;
?>

<?php
$userb = $_SERVER['REMOTE_USER'];
echo 'Current user is'.$userb.;
?>

<?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>";
}
?>
Link to comment
Share on other sites

My advice would be to do this...

1. Create a serverparams.php page that looks like this:

[code]
<?php
foreach ($_SERVER as $k => $v){
  echo "$k - $v<br>\n";
}
?>
[/code]

2. Upload that to an area within your secured folder.
3. Open the serverparams.php file in your browser, you'll be asked to login.
4. Check that the PHP_AUTH_USER and REMOTE_USER actually contain values.

Let me know the outcome.

Regards
Huggie
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.