HTTP-Authentication and Windows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Data
Forum Newbie
Posts: 15
Joined: Tue Jun 25, 2002 4:14 am
Location: Aberdeen, Scotland

HTTP-Authentication and Windows

Post by Data »

I have Apache and PHP installed on Windows XP Home.
I've been trying to do some basic http-authentication:

Code: Select all

<?php
if (!isset($PHP_AUTH_USER)) 
{
	// If empty, send header causing dialog box to appear
	header('WWW-Authenticate: Basic realm="My Private Stuff"');
	header('HTTP/1.0 401 Unauthorized');
	echo 'Authorization Required.';
	exit;
}
else 
{
	echo "<p>You have entered this username: $PHP_AUTH_USER<br>";
	echo "You have entered this password: $PHP_AUTH_PW<br>";
	echo "The authorization type is: $PHP_AUTH_TYPE<p>";
}

?>
I'm sure that this should work correctly (I am not outputting anything before the header), however I always get a 500 Internal Server Error.
Will HTTP-Authentication work in Windows?
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post by hedge »

no, it doesn't work on windows. you need to authenticate against a db or some other method.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you're running PHP as an Apache module the HTTP-authentication should be available to you even if you are on Windows.
http://www.php.net/manual/en/features.http-auth.php

The problem is likely to be that you should be using things like $_SERVER['PHP_AUTH_USER'] instead of $PHP_AUTH_USER - check the examples shown in the link above which have been written to work in the latest versions of PHP where register_globals (viewtopic.php?t=511) is off by default.

Mac
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post by hedge »

Sorry for the mis-information. I didn't read close enough, and assumed IIS
Post Reply