How do I resolve the "Cannot modify header information..." e

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
repp9418
Forum Newbie
Posts: 10
Joined: Thu Jan 17, 2008 10:37 am

How do I resolve the "Cannot modify header information..." e

Post by repp9418 »

My environment is:
PHP 5.2.5
Apache 2.2.8
W2k3
IIS 6.0

I am trying to run the following code to test a connection to a DB server. There are not spaces above or below the PHP tags.

Code: Select all

<?php 
include('adodb/adodb.inc.php'); 
echo 'hello world'; 
 
$dbora = ADONewConnection('oci8'); 
echo '<br>connection created<br>'; 
flush(); 
$dbora->Connect('XXX', 'hrs', 'XXX', 'SID');  //TNS:Connect timeout 
echo '<br>connection established<br>'; 
flush(); 
?>
In this code I was getting a timeout error. I put the flush calls in so the error would display on the page right away. The flush tags are causing the following errors.

Code: Select all

[06-Jun-2008 14:28:41] PHP Warning:  Cannot modify header information - headers already sent in Unknown on line 0
[06-Jun-2008 14:28:41] PHP Warning:  Cannot modify header information - headers already sent in Unknown on line 0
 
The errors are generated only in Apache. In IIS I do not get these errors. Does anyone know why?

Thanks
User avatar
Jaxolotl
Forum Contributor
Posts: 137
Joined: Mon Nov 13, 2006 4:19 am
Location: Argentina and Italy

Re: How do I resolve the "Cannot modify header information..." e

Post by Jaxolotl »

did you try searching before asking? this topic is frequently asked

the server is telling you that you already send the http headers and you're trying to do it again when it's not possible to send them more than once

Check if you have error reporting to E_ALL and tell us what it's coming out, maybe something there is sending an unespected header

for example you are sending echo 'hello world'; to the output, if for any reason ADONewConnection('oci8') or Connect('XXX', 'hrs', 'XXX', 'SID') is trying to send another header like header('Location: something') you're in trouble

PHP MANUAL wrote: Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
http://www.php.net/header
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: How do I resolve the "Cannot modify header information..." e

Post by Benjamin »

Are you even sending headers anywhere?
repp9418
Forum Newbie
Posts: 10
Joined: Thu Jan 17, 2008 10:37 am

Re: How do I resolve the "Cannot modify header information..." e

Post by repp9418 »

The above code is EXACTLY what I am using. There is nothing more to it. I browser to test.php, which is nothing more than the code above.

I promise I have googled this for 2 days before I posted it on here. I am not calling header() and I do not have any spaces above or below the <?php ?> tags. Those were the only responses people gave for resolving this issue.

At this point I am thinking this is a php.ini setting or an Apache setting that is causing this, but I am not sure which one. I was hoping someone could point me in the right direction.
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Re: How do I resolve the "Cannot modify header information..." e

Post by Rovas »

Try using this function to see what headers the server sent and from where. The comments on that page are helpful. You might have the options for caching files activated, when the caching options are activated they usually send headers for caching. For caching activation you have to check the IIS configuration. I haven' t worked with IIS 6 only with the v5.1 version. From what I remembered you have to look in the Properties window for folder that contains the site. There in one tab is the caching options. I' m not sure because I haven' t worked with IIS from about 2 years.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: How do I resolve the "Cannot modify header information..." e

Post by Jonah Bron »

This code may not be sending any header information, so it is likely that the ADONewConnection class is sending the headers, after you have echoed. Try running the same code without any echos, and see if it works then. Am I correct in assuming that the echos are for debugging purposes?
Post Reply