faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

8 of 13 people (62%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How can I get users via PHP after .htaccess login?

Dec 20th, 2001 08:46
MyNameIs Monkey, Frank Hoechel, http://www.php.net/manual/en/features.http-auth.php


Pop the htaccess request using PHP in the first place:
<?php
  if(!isset($PHP_AUTH_USER)) {
    header("WWW-Authenticate: Basic realm=\"Your Realm\"");
    header("HTTP/1.0 401 Unauthorized");
    echo "Your custom 401 message here\n";
    exit;
  } else {
    echo "<p>Hello $PHP_AUTH_USER.</p>";
    echo "<p>Your password is $PHP_AUTH_PW.</p>";
  }
?>
This will *only* work when PHP is running as an Apache module.