Jump to content


Photo

user authentication


  • Please log in to reply
4 replies to this topic

#1 sonners

sonners
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 October 2006 - 03:08 PM

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>";
}
?>

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 17 October 2006 - 04:17 PM

My advice would be to do this...

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

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

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 sonners

sonners
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 October 2006 - 07:28 PM

HuggieB - thanks so much for your reply!

I did what you said and
PHP_AUTH_USER
PHP_AUTH_PW
REMOTE_USER

all have values that are correct.

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 18 October 2006 - 02:33 AM

In that case, just use the following...

<?php
$username = $_SERVER['PHP_AUTH_USER']; // Notice the single quotes
echo "Welcome {$username}<br>\n";
?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 sonners

sonners
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 18 October 2006 - 09:51 AM

thanks HuggieBear - that works perfect. It looks like my syntax was all wrong!
I had to include the php file as an SSI to get the php to render but it works. Txs again!

s




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users