Re: newbie question - apache-win2K-authentication
| From: | Miles Thompson | Date: | Thu, 02 Aug 2001 15:17:30 +0000 |
| Subject: | Re: newbie question - apache-win2K-authentication | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-60921@lists.php.net to get a copy of this message | ||
Shari,
The following script works, although I'm authenticating against a database.
The include files are not needed, I use them just so that I have only one place to store my database name, etc., and to display a standard header and footer.
You can put your stuff in after the "else". Thanks to Rasmus Lerdorf, this was pinched from one of his articles.
How many browsers have you tried this with? Do you have both http 1.0 and 1.01 protocols checked off in your browser settings?
One thing is critical, THERE MUST BE NO WHITE SPACE AT ALL between the beginning of the file and when the headers are issued. For example, one blank line at the top of the file reduces this to junk.
HTH - Miles
--------- top of the file -----------
<? require( "dbname.inc" );
function authenticate() {
Header("WWW-authenticate: basic realm=\"Auction Maintenance\"");
Header("HTTP/1.0 401 Unauthorized");
$title="Invalid Login";
include( 'header.inc' ); ?>
In order to proceed you will need a valid username/password.
<?include ("footer.inc");
exit;
}
if(!isset($PHP_AUTH_USER)) {
authenticate();
} else {
mysql_pconnect("localhost","root")
or die("Unable to connect to SQL server");
mysql_select_db( "$auction" ) or die("Unable to select database");
$login_id=strtolower($PHP_AUTH_USER);
$query = mysql_query("select * from admin where cAdminId='$login_id'".
" and cPassword='$PHP_AUTH_PW'");
if(!mysql_num_rows($query))
{
authenticate();
}
else
{
include( 'header.inc' );
}
}
?>
At 07:42 AM 8/2/01 -0700, Shari Fletcher wrote:
Hi all --- I'm having some trouble getting basic authentication working. Either that or my privileges are screwed up, or something. I am running Apache on Windows 2000 and PHP4. I've searched newsgroups, this mailing list, various FAQs and the manual, I think my eyes are crossing. I've got a feeling either its so simple I can't see it, or its not possible. I'm hoping someone has a quick idea about what's going on. Here's my story: My authentication script is from this example. If I leave it as is, I can authenticate and I receive the error: malformed = header from script. Bad header=3DHTTP/1.0 401 Unauthorized: =e:/php/php.exe If I change the unauthorized header to this: header("Status: 401 Unauthorized"); I cannot authenticate, though the user id and password is correct. Thanks in advance ! Shari My script:if (!isset($PHP_AUTH_USER)) {// If empty, send header causing dialog box to appear header('WWW-Authenticate: Basic realm="securedf"'); header('HTTP/1.0 401 Unauthorized'); echo 'Authorization Required.'; exit; }// If not empty, display values for variableselse {echo " <P>You have entered this username: $PHP_AUTH_USER<br> You have entered this password: $PHP_AUTH_PW<br> The authorization type is: $PHP_AUTH_TYPE</p> "; }-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net