malformed header: Apache for win and php

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
CEO
Forum Newbie
Posts: 1
Joined: Sat Feb 08, 2003 2:25 am

malformed header: Apache for win and php

Post by CEO »

Hi, everybody.
I have a problem with PHP authentication code.
I am using Apache as a server on Win2000Profesional.
When I am executing "authenticate" function which is described in a
book, error message is desplayed in the browser : Something about an
internal server error.
So can you help about this? Thanks


Here is the code:

Code: Select all

<?php
if (!isset($PHP_AUTH_USER))
	&#123;
	HEADER ("WWW-authenticate: basic realm="Restricted area"");
	HEADER ("HTTP/1.0 401 Unauthorized");
	echo "You failed to provide the correct password...\n";
	exit;
	&#125;
else
	&#123;
	mysql_select_db("warranty");
	$user_id=strtolower($PHP_AUTH_USER);
	$result=mysql_query("SELECT password FROM admin " . "WHERE user = 
'$username'");
	$row = mysql_fetch_array ($result);
	if ($PHP_AUTH_PW != $row&#1111;"password"])
		&#123;
		HEADER ("WWW-authenticate: basic realm="Restricted area"");
		HEADER ("HTTP/1.0 401 Unauthorized");
		echo "You failed to provide the correct password...\n";
		exit;
		&#125;
	&#125;
?>


And the error, which was displayed in browser:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your
request.

Also I checked in Apache error.log file, and there was the following error:

Tue May 01 22:42:49 2001] [error] [client 127.0.0.1] malformed header from script. Bad
header=HTTP/1.0 401 Unauthorized: c:/php/php.exe


That's it.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

afaik you're not allowed to send the 401-header from the cgi-version of php.
If possible switch to the apache-module.
Did you take the installer or the zip-version from php.net ?
Post Reply