php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15409 Printing header works only if followed by a print statement
Submitted: 2002-02-06 16:05 UTC Modified: 2002-02-06 16:33 UTC
From: priebe at mi-corporation dot com Assigned:
Status: Closed Package: Apache related
PHP Version: 4.1.1 OS: RH Linux 7.2 (kernel2.4.9-13smp)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: priebe at mi-corporation dot com
New email:
PHP Version: OS:

 

 [2002-02-06 16:05 UTC] priebe at mi-corporation dot com
The following script works when php is called from the command line:

<?php
print header("Location: http://www.yahoo.com/");
exit;
?>

[myhost] php test.php
Location: http://www.yahoo.com/
Content-type: text/html

But when called via the Apache server (1.3.20), I get nothing (and nothing in the error logs, so I don't think PHP is crashing):

[myhost] telnet localhost 80
Trying localhost...
Connected to localhost.
Escape character is '^]'.
GET /test.php HTTP/1.0

Connection closed by foreign host.

But if I print some non-empty string after I print the header, it works:

<?php
print header("Location: http://www.yahoo.com/");
print "\n";
exit;
?>

[myhost] telnet localhost 80
Trying localhost...
Connected to localhost.
Escape character is '^]'.
GET /test.php HTTP/1.0

HTTP/1.1 302 Found
Date: Wed, 06 Feb 2002 21:01:52 GMT
Server: Apache/1.3.20 (Unix)  (Red-Hat/Linux) mod_ssl/2.8.4 OpenSSL/0.9.6b DAV/1.0.2
Location: http://www.yahoo.com/
Connection: close
Content-Type: text/html

This is not restricted to the Location header; other headers do not display either, unless followed by some non-null print statement.




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-06 16:10 UTC] derick@php.net
Who told you you can print a header like that?
Anyway... the headers are indeed only send when some output is done.
 [2002-02-06 16:13 UTC] priebe at mi-corporation dot com
Of course the headers are only sent when output is done.  I understand that.  But the problem is that if there is no output other than the header, the header is not displayed at all!

I just realized that a patch I quickly threw together for bug 15209 may be to blame.  I'm quite confident that 15209 is a legitimate bug that needs attention (although nobody seems to have done anything with it).  Before anybody wastes time on this bug, 15209 should take priority.
 [2002-02-06 16:14 UTC] derick@php.net
But I was unable to reproduce it here on RH 7.2/4.1.1

Derick
 [2002-02-06 16:17 UTC] priebe at mi-corporation dot com
OK -- if you can't reproduce it, it's likely the result of the patch I applied to our copy.  My apologies for entering this bug report before testing against a standard 4.1.1 install.

But if you happen to know how to attack 15209...  :-P
 [2002-02-06 16:18 UTC] derick@php.net
Would you still be so kind to test with standard 4.1.1?
(and I morked 15209 as critical for now)

Derick
 [2002-02-06 16:33 UTC] priebe at mi-corporation dot com
I just rebuilt PHP 4.1.1 without my patch, ran the test, and I did in fact get the headers as expected.  Sorry for the false alarm; I'm closing this bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 14:01:30 2024 UTC