Re: PHP Authentication on Apache
| From: | Alfredo Yong | Date: | Tue, 04 Sep 2001 00:42:27 +0000 |
| Subject: | Re: PHP Authentication on Apache | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-65812@lists.php.net to get a copy of this message | ||
Yes. It works. It is great.
if(!isset($PHP_AUTH_USER) or $PHP_AUTH_USER != "myuser" or $PHP_AUTH_PW != "mypassword") {
Header("WWW-Authenticate: Basic realm=\"Only authorizeds web\"");
Header("HTTP/1.0 401 Unauthorized");
echo "ha!\n";
exit;
}
Lynn Holt wrote:
Hi all, Trying PHP for the first time. Snached the authentication code from the docs and put it in phpauth.php. When I surf to it, it just asks for my user and password again and again If I hit Cancel, it prints the little message just fine. Here's the code in case I'm the only one to RTFM: ------- Example 17-1. HTTP Authentication example <?php if(!isset($PHP_AUTH_USER)) {header("WWW-Authenticate: Basic realm=\"My Realm\""); header("HTTP/1.0 401 Unauthorized"); echo "Text to send if user hits Cancel button\n"; exit;} else {echo "<p>Hello $PHP_AUTH_USER.</p>"; echo "<p>You entered $PHP_AUTH_PW as your password.</p>";} ?> --------------------- I have php 4.0.6 installed as a module(DSO) in apache 1.3.20 and everything else I've tried seems to work. Any Ideas? Anybody know if this is supposed to work? Should I stick with AuthPG and forget PHP authentication? BTW I don't have AuthType set in .htaccess or httpd.conf. Lynn Getting old isn't hard, all you got to do is live long enough......or fast enough.