Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Authentication

Status
Not open for further replies.

chpicker

Programmer
Joined
Apr 10, 2001
Messages
1,316
I cannot seem to get PHP Authentication to work. I tried the example given in the PHP documentation, and that doesn't work, either. Here is what I tried:
Code:
<?php
  if (!isset($_SERVER['PHP_AUTH_USER'])) {
   header('[URL unfurl="true"]WWW-Authenticate:[/URL] 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>";
  }
?>
When I attempt to run this page from my web site, the authentication dialog pops up as expected...three times, followed by the 'Text to send if user hits Cancel button' page, which was NOT expected.

My web server is running PHP 4.3.3 under Apache. I don't know if it is running as a server module or CGI, though, and I think that might be my problem. However, I don't know what the behavior would be in that case. Can anyone confirm this? If that's not the problem, does anyone have any ideas?

Thanks,

Ian
 
The first full sentence on the page of the online manual from where you got that example code states: The HTTP Authentication hooks in PHP are only available when it is running as an Apache module and is hence not available in the CGI version.

If you're running PHP as a CGI, you can't perform HTTP authentication using PHP. You'll have to implement your own HTML login system.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Yes, I know that. However, as I said, I don't actually KNOW if it is running as an Apache module or as a CGI module. It's not my server.

What I want to know is if the behavior I am seeing indicates that it is running in CGI mode or if it might be something else instead.
 
Insufficient data for a meaningful answer. There is a great deal of weirdness that might cause the problem.


But you can resolve the "Is it because PHP is running as a CGI?" question by simply asking your hosting provider whether PHP is running as a module or as a CGI.

It's possible, I suppose, that examining the output of phpinfo() might give one clues, too.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top