php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27091 Reproduceable CGI error (misbehaving header issue)
Submitted: 2004-01-29 17:36 UTC Modified: 2004-01-29 17:59 UTC
From: phil at pelanne dot com Assigned:
Status: Not a bug Package: IIS related
PHP Version: 4.3.4 OS: Windows Server 2003
Private report: No CVE-ID: None
 [2004-01-29 17:36 UTC] phil at pelanne dot com
Description:
------------
This concerns the misbehaving header error that happens with IIS 6 (and 5, I thinks) and PHP running as a CGI, usually after some database query (in this case on MSSQL).  

I've found a way to reproduce it (and a workaround that people can take away).  Maybe there's something that can be done from the PHP side to alleviate this?  In any case, a simple code change seems get around it (and may shed some light on the cause of this, if it is indeed a bug).

If you create the two files in the reproduce code, about half the time you get a CGI error.  If you change the header redirect line to use the path from the site root(this example assumes you're in the root directory of your site, so I'm just adding a slash):

header("location: file2.php"); changes to header("location: /file2.php");


...you never get that CGI error, even though if both of the files are in the root directory of your site, the location file2.php should be the same as the location /file2.php

This is reproduceable with the newest stable snapshot as well (as of 1/29/04)

Hope this helps you guys (and maybe others)- thanks for a great language!

Reproduce code:
---------------
//file1.php - replace your database host, login and password.
//Any query to any DB will do, but this Northwind database
//comes with mssql, so it's convenient
<?
$msconnect=mssql_connect("your DB host","your_login","your_password");
$msdb=mssql_select_db("Northwind",$msconnect);
$msquery = "select titleofcourtesy,firstname,lastname from employees";
$msresults= mssql_query($msquery);
header("location: file2.php");
?>

//file2.php - no actual php here
Go back to <a href="file1.php">file1.php</a>

Expected result:
----------------
One would expect to see 

"Go back to file1.php"

each time you click on the file1.php link.

Actual result:
--------------
We get this sporadic error:
"CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers."

...Maybe 50% of the time - until we change that path in the header to an absolute path, then we never get the error.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-29 17:40 UTC] derick@php.net
You always need to use a FULL absolute path here, like:

header("location: http://www.example.com/file2.php");


 [2004-01-29 17:59 UTC] phil at pelanne dot com
Just as followup, putting the full URI still produces this sporadic error message in this scenario.  

The only way it seems to work consistently is to use header("location: /file2.php") (even though now I see that it's not the OFFICIAL use of the header function).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 05:01:33 2024 UTC