1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Authentication Not Working

Discussion in 'PHP' started by webmaster_TSU, Dec 13, 2007.

  1. #1
    I have this code on the page:
    <?php
    	/*This just checks to ensure they filled in username and password.*/
    	if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_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 "Hello ".$_SERVER["PHP_AUTH_USER"].".<P>";
    		echo "You entered ".$_SERVER["PHP_AUTH_PW"]." as your password.<P>";
    	}
    ?>
    Code (markup):
    Everytime I run the page, it keeps popping up with the user name/password prompt, even when I enter both a user and password. It eventually just fails...as far as I know this should be working fine, and I don't know how to resolve it.
     
    webmaster_TSU, Dec 13, 2007 IP
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That code sample works fine for me. AFAIK you need PHP to be installed as module for it to work. If your PHP is installed in CGI mode, then the example above won't work, because $_SERVER['PHP_AUTH_USER'] variable is not being set.
     
    hogan_h, Dec 13, 2007 IP
    webmaster_TSU likes this.
  3. webmaster_TSU

    webmaster_TSU Peon

    Messages:
    449
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok, so aside from installing it, are there any work arounds.
     
    webmaster_TSU, Dec 14, 2007 IP
    hogan_h likes this.
  4. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0