PHP sends a '401 Authorization required' to your browser (just like apache) and it also gets the user/password info
Code example: <?php if(!isset($PHP_AUTH_USER)) { Header("WWW-Authenticate: Basic Realm=\"Secret Page\""); Header("HTTP/1.0 401 Unauthorized"); echo "You did not log in correctly...\n"; exit; # exit wil stop php from parsing the rest of the script } else { echo "Hello $PHP_AUTH_USER. You entered $PHP_AUTH_PW as your password"; } ?> In this example no user/passwd checking is done... just replace the 'welcome' message with your mysql/ldap check routine and voila ! regards, Ewout de Boer ----- Original Message ----- From: <[EMAIL PROTECTED]> To: "Ewout de Boer" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Thursday, November 14, 2002 5:42 PM Subject: Re: [PHP] PHP Auth with Apache > > I'm now understanding how you can get PHP to present you with a username > and password promt just like APache would do if you had a .htaccess file > in the directory you were trying to enter. Great idea but it seems that it > would be easier to just use the .htaccess file in the directory. > > What I've been trying to find out is how to pass through a .htaccess file > if someone has already passed an database authentication lookup in PHP. > > I have an area on my site "Special Publications" where users login and > their username and password is checked against a MySQL database. One field > in their user records is the URL to their directory on our server. Each > one of these directories is protected via .htaccess. What I would really > like to do is have them redirected to their URL if they pass > authentication and not have them enter their username and password again. > Is their a way to do this? > > Thanks, > > Ed > > > > On Wed, 13 Nov 2002, Ewout de Boer wrote: > > > in httpd.conf > > > > <Directory /scriptdir> > > AllowOverride AuthConfig > > </Directory> > > > > > > More info at http://httpd.apache.org/docs/mod/core.html#allowoverride > > > > > > regards, > > > > Ewout > > > > > > ----- Original Message ----- > > From: "Alexander Bemme" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > Sent: Wednesday, November 13, 2002 12:02 PM > > Subject: [PHP] PHP Auth with Apache > > > > > > > Hi, > > > i got a little problem (i hope so) > > > > > > I have installed Apache 1.3.26 and PHP 4.2.3 as module. > > > > > > I used the example from www.php.net to do a PHP authentication, > > > but it didn't work, the pop appears but i can't login. > > > > > > In PHPManual is someting about "AuthType" but nothing about how > > > to fix it. > > > > > > Can someone help out? > > > > > > Thanks > > > > > > --Alex > > > > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php