Forum Moderators: coopster

Message Too Old, No Replies

Need Help With Header Information

         

JonNewbie

9:58 am on Oct 1, 2007 (gmt 0)

10+ Year Member



I received the following error message when clicking on an "update" button on estore software :

Warning: Cannot modify header information - headers already sent by (output started at /home/jon2007/public_html/admin/includes/configure.php:75) in /home/jon2007/public_html/admin/includes/functions/general.php on line 18

Opening up the general.php file, I find the following script and affected line 18 :

// Redirect to another page or site
function tep_redirect($url) {
global $logger;

header('Location: '.$url); ......line 18

if (STORE_PAGE_PARSE_TIME == 'true') {
if (!is_object($logger)) $logger = new logger;
$logger->timer_stop();
}

exit;
}

I would greatly appreciate if someone can help me troubleshoot the affected line 18. I have tried changing the syntax many times by changing the positions of the inverted comma and dot.

The best result I had using :
header ('Location: ''.$url)

resulted in a new error meassage :

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/jon2007/public_html/admin/includes/functions/general.php on line 20

Thanks,
Jon Newbie

dreamcatcher

10:05 am on Oct 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Jon,

The second error is simply because of a mis-match of quotes. The header error is because you cannot send data to the browser before you call this function. The error is basically telling you that data is being sent to the browser in your 'configure.php' file first. This could be actual data or simply whitespace.

Sort that out and your error will disappear.

dc

Habtom

10:07 am on Oct 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have tried changing the syntax many times by changing the positions of the inverted comma and dot.

That is not where the error is actually. The problem is caused by any kind of output prior to line 18. Any output including spaces, or any characters, error messages of any kind.

Clean up the lines ahead of the header redirect, and you should be ok.

Habtom

10:10 am on Oct 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



dreamcatcher beat me to it. It is not his first time. :)

[edited by: Habtom at 10:10 am (utc) on Oct. 1, 2007]

JonNewbie

12:48 pm on Oct 1, 2007 (gmt 0)

10+ Year Member



Hi DC & Habtom,

Thanks for your replies. If I understand you all correctly, the error on line 18 has nothing to do with syntax at all, meaning its syntax in its original state is OK. And the second error message I received is because of my making a change, resulting in a "mismatch of quotes"

I have opened up the configure.php file mentioned in the first error message. This is a file.. almost all consisting of "define" statements , and the scripts for this fle end with a closing tag on line 73. Therefore line 75 mentioned in the error message is actually an empty space or whitespace as you call it.

The thing is how do I call the header function before sending data to the browser? I have tried adding some blank rows so that the closing tag of configure file ends on line 75. When I re-run, the same error appears, this time quoting line 77 instead of line 75 for the configure file, and line 18 for the general.php file.

I would appreciate if you can give me some direction on where to make the changes.

Thanks,
Jon

PHP_Chimp

7:16 pm on Oct 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you made sure that all of your lines of code end with ; and that you have everything in matching {}'s?
As if you are missing either then you can get the error reported as the final line of code.
Something in a switch statement, if/else/elseif type statements can be a bit of a pain to track down, as a lot of lines of code may be skipped to give you the error at the end of your script.

To stop the headers being sent to the browser you need to have had something sent to the browser. As php is parsed just before the content is sent to the browser php script before the header isnt a problem. However having the <?php tag indented by 1 or more spaces (if you are putting all the php at the top of your page) would result in that whitespace character being sent to the browser before it starts on the php. So your header error. If it is just php at the top of the page then so long as you havent echo'd any output then nothing will have been sent to the browser until you send your header info.

Habtom

8:01 am on Oct 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The thing is how do I call the header function before sending data to the browser?

If you are calling the header function, do you still need to display data to the browser? Or is it some kind of "you are being transfered" messages?

One way to go forward is to hold the output in a variable or so, and send the header and then display the output if this makes sense.

The best thing to do is though, to remove any kind of outputs before the header is sent, anyway you might not need them as well.

Habtom

JonNewbie

5:00 pm on Oct 4, 2007 (gmt 0)

10+ Year Member



Hi All ,

I am back...with Good News that the error message on header information has been solved. I spent the last few days following up on the clues you all gave me, and finally got it solved.

As the original error message mentioned that the header output has started in another file (configure.php) on line 75 even before the header function was read in general.php file, I started looking in configure.php file.

I just know that I was looking for mismatched quotes, curly brackets and possibly some odd blank spacing in the script. I was comparing the script printout of the original file against the actual file in the server, when with a good dose of divine providence, I noticed a line spacing between line 68 and line 70 on the hosted file...which was not shown in the printed script.

I deleted the line spacing, re-ran the program and suddenly it ran smoothly and displayed perfectly the admin page of my estore.

I would like to thank you guys for the useful tips, and for pointing the direction I need to take to solve this difficult error. Once again, my best wishes to you all in whatever work you are undertaking.

Yahoooo!

Best regards
Jon Newbie

dreamcatcher

6:01 pm on Oct 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it sorted Jon.

dc