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


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

Feb 24th, 2008 19:46
dman, MyNameIs Monkey, Frank Hoechel, http://www.ttnr.org

Pop the htaccess request using PHP in the first place:
  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";
  } 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.