Jump to content


Corporate Sponsors


Latest News: (loading..)

* * * * * 1 votes

"Headers already sent..."


  • You cannot reply to this topic
13 replies to this topic

#1 germ

  • Community Member
  • 13,586 posts
  • Real Name:Jim
  • Gender:Male
  • Location:USA (GMT-6)

Posted 12 June 2011, 22:32

"Headers already sent" help contribution
If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

"Headers already sent" - The definitive help

"Cannot redeclare ..." - How to find/fix it

SSL Implementation Help

Like this post? "Like" it again over there >

#2 sunshynecraftsbeads

  • Community Member
  • 144 posts
  • Real Name:Tracie Peters
  • Gender:Female
  • Location:British Columbia, Canada

Posted 23 June 2011, 23:16

Hi Jim,

Thank you for the information and the contribution. I have installed it and brought up the output start at folder as mentioned in your read me notes. The following is what comes up when I hit go.

I opened the php file and reviewed everything looking for these the comments on the report but there is nothing that has the <?php[0D][0A] or the ?>[0D][0A][0D][0A] mentioned ? I even did a search within the php file.

It says that the php file has 91 lines but when I open my php file in code editor it shows my last line to be 90 and it says ?>


Am I missing something here Jim. Please advise when you have a minute. Thank you so much in advance for provided me with more information. I will also continue to check things in the mean time. I am not sure why this has happened since I have not touched my shipping folders for weeks.



Quote

/home/sunshyn1/public_html/includes/modules/shipping/airinternational.php has 91 lines.
The PHP start tag is on line 1.
The PHP end tag is on line 90.
Contents from start of file to the PHP start tag:

<?php[0D][0A]

-------------------------
Contents from PHP end tag to end of file:

?>[0D][0A]
[0D][0A]


Error Messages:

The closing PHP tag is not on the last line in the file.


-------------------------
The requested line [92] is out of range.


#3 toyzonline

  • Community Member
  • 317 posts
  • Real Name:Ricardo
  • Gender:Male
  • Location:Cheshire, England

Posted 23 June 2011, 23:24

Put your cursor after the ?> and press delete.

I know it sounds daft but dont reply on a visual inspection

Ricardo

#4 sunshynecraftsbeads

  • Community Member
  • 144 posts
  • Real Name:Tracie Peters
  • Gender:Female
  • Location:British Columbia, Canada

Posted 23 June 2011, 23:32

Thank you so much Jim & Ricardo. That did the trick. I am up and running again with no errors.
You guys are the best !!!!!! :thumbsup:

#5 sunshynecraftsbeads

  • Community Member
  • 144 posts
  • Real Name:Tracie Peters
  • Gender:Female
  • Location:British Columbia, Canada

Posted 23 June 2011, 23:42

Quote

Put your cursor after the ?> and press delete.

I know it sounds daft but dont reply on a visual inspection

Ricardo


Thank you so much Jim & Ricardo. That did the trick. I am up and running again with no errors.
You guys are the best !!!!!! :thumbsup:

#6 BretSpark

  • Community Member
  • 32 posts
  • Real Name:Bret Spark

Posted 23 August 2011, 15:09

Hi Guys,
i am haveing a small problem with this addon, i have installed and configured it as per the installing guide. everything shows up ok when i enter it under the admin section.
The problem i have is the editor seems to add extra characters. for example if i type "testing" it comes up as

rn testing
rn

Any ideas? for some strange reason it seems to be placing Windows Return characters in my text.

Regards

Bret

#7 germ

  • Community Member
  • 13,586 posts
  • Real Name:Jim
  • Gender:Male
  • Location:USA (GMT-6)

Posted 27 August 2011, 15:36

View PostBretSpark, on 23 August 2011, 15:09, said:

Hi Guys,
i am haveing a small problem with this addon, i have installed and configured it as per the installing guide. everything shows up ok when i enter it under the admin section.
The problem i have is the editor seems to add extra characters. for example if i type "testing" it comes up as

rn testing
rn

Any ideas? for some strange reason it seems to be placing Windows Return characters in my text.

Regards

Bret
I'm thinking you posted in the wrong topic.
:blush:

I'll post the contents of the "readme" that is in my contribution so you won't have to download it.

Quote

"Headers already sent"
----------------------

The offical explanation:

http://www.oscommerce.info/confluence/display/OSCDOC22/Error+*+Cannot+Add+Header+Information

Using osC you can't have output to the browser before the session is started (normally in /catalog/includes/application_top.php).

What this really boils down to is the opening php tag ( <?php ) must be at the beginning of the php file, and you cant have anything more that the O/S [eol] after the closing php tag ( ?> ).

If you have any blank lines or spaces or other characters (seen or unseen) in front of the opening tag or after the closing tag you can get the "Headers already sent" error.

Saving a file in UTF-8 format with the Byte Order Mark (BOM) will also cause this error.

The thing about it is since most of the time it's "whitespace(s)" (jargon for "what you can't see") it can be difficult to find the source, let alone fix it.

Then to add "insult to injury" the PHP errors that appear on the page aren't much help.

A few examples taken from the forum:

Warning: Cannot modify header information - headers already sent by (output started at /htdocs/public/www/includes/languages/espanol/modules/payment/transfer.php:19) in /htdocs/public/www/includes/functions/general.php on line 33

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /mounted-storage/myshop.com/index.php(1) : eval()'d code:37) in /mounted-storage/myshop.com/includes/functions/sessions.php on line 102

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/html/includes/functions/database.php:307) in /home/html/includes/functions/sessions.php on line 203

Notice that in each case TWO FILES are mentioned! So where does one look?

The very simple answer is: ALWAYS look in the file where the error message says "output started at".

And at the end of that part of the error message a "line number" is given.

I've writen a small helper utility if you have difficulties finding the problem.

Upload the headsent.php file in this contribution into your "catalog" folder. Then access it with your browser.

You are then presented with a "File:" box, an "Optional Line #:" box and a "Do it" button.

Most times just type the the path to the file with the error into the "File:" box then hit [enter] or click the "Do it" button.

More on the "Optional Line #:" box later.

Let's look at each if the three example errors and I'll expand on the contribution's use.

Example No. 1
-------------

Warning: Cannot modify header information - headers already sent by (output started at /htdocs/public/www/includes/languages/espanol/modules/payment/transfer.php:19) in /htdocs/public/www/includes/functions/general.php on line 33

This person would upload headsent.php into the "www" folder, and in the box type: includes/languages/espanol/modules/payment/transfer.php

The offending line in that case is line number 19.

Example No. 2
-------------

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /mounted-storage/myshop.com/index.php(1) : eval()'d code:37) in /mounted-storage/myshop.com/includes/functions/sessions.php on line 102

This person would upload headsent.php into the "myshop.com" folder, and in the box type: index.php

The offending line in that case is line number 1. This shop had been hacked.

Example No. 3
-------------

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/html/includes/functions/database.php:307) in /home/html/includes/functions/sessions.php on line 203

This person would upload headsent.php into the "/home/html/" folder, and in the box type: includes/functions/database.php

The offending line in that case is line number 307.

Now, more about the "Optional Line #:" box.

Most of the time the "Headers already sent" error is because of "whitespaces" or other content at the beginning or end of a file.

I have seen it where there is a php "echo" or other content in the middle of a file that shouldn't be there.

Mostly from downloaded contributions where the developer had some "debug" code they forgot to remove before uploading the contribution.

So if you have a "Headers already sent" problem with a file and the error is on line number say 199 and the file has say 247 lines you know the problem isn't at the end of the file.

And it probably doesn't have 198 blank lines at the beginning of the file so that's where you'd use the "Optional Line #:" box to have the program display that line from the file in your browser.

What should the ouput look like when you run the program?

Normally like this (UNIX O/S):

Contents from start of file to the PHP start tag:

<?php[0A]

-------------------------
Contents from PHP end tag to end of file:

?>[0A]

Or like this (Windowz O/S):

Contents from start of file to the PHP start tag:

<?php[0D][0A]

-------------------------
Contents from PHP end tag to end of file:

?>[0D][0A]

If you have a blank line at the beginning of the file it might look like this:

Contents from start of file to the PHP start tag:

[0A]<?php[0A]

If you saved a file in UTF-8 format with the BOM it might look like this:

Contents from start of file to the PHP start tag:

[EF][BB][BF]<?php[0A]

If you have an extra blank line at the end of the file it might look like this:

Contents from PHP end tag to end of file:

?>[0A][0A]

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

"Headers already sent" - The definitive help

"Cannot redeclare ..." - How to find/fix it

SSL Implementation Help

Like this post? "Like" it again over there >

#8 ssfcsv

  • Community Member
  • 19 posts
  • Real Name:Stacy

Posted 23 January 2012, 23:48

Thank you for writing this Jim.

#9 apolyshow

  • Community Member
  • 242 posts
  • Real Name:Andreas
  • Gender:Male

Posted 18 February 2012, 17:16

i am having this issue

Warning: Cannot modify header information - headers already sent by (output started at /home/iliofosg/public_html/eshop/downunder/includes/template_top.php:14) in /home/iliofosg/public_html/eshop/downunder/includes/functions/general.php on line 35

and with the headsent.php i am taking this

O/S = Linux.
downunder/includes/template_top.php has 74 lines.
The PHP start tag is on line 1.
The PHP end tag is on line 72.
Contents from start of file to the PHP start tag:

<?php[0A]

-------------------------
Contents from PHP end tag to end of file:

?>[0A]
[0A]
<div[20]id="contentText">[0A]


Error Messages:

The closing PHP tag is not on the last line in the file.


-------------------------
Extended contents of the requested line [14] are:

<html[20]<?php[20]echo[20]HTML_PARAMS;[20]?>>[0A]

-------------------------
Raw contents of the requested line [14] are:

>


What do i have to do?
One amateur made the Arc, 5.000 pro made the Titanic...

#10 ogwinilo

  • Community Member
  • 150 posts
  • Real Name:Felix
  • Gender:Male

Posted 28 February 2012, 07:54

I have a similar problem. I have deleted spaces on each ends of the file, replaced the languages.php file with one that is exactly the same and working in another site, but still no joy.

This is the message received;
Deprecated: Function eregi() is deprecated in /home/woiqqwab/public_html/yebocom/admin/includes/classes/language.php on line 87

Warning: Cannot modify header information - headers already sent by (output started at /home/woiqqwab/public_html/yebocom/admin/includes/classes/language.php:87) in /home/woiqqwab/public_html/yebocom/admin/includes/functions/general.php on line 22

Any help will be appreciated

Regards

Felix

#11 MrPhil

  • Community Member
  • 3,294 posts
  • Real Name:Phil
  • Gender:Male

Posted 28 February 2012, 18:57

Your problem is that your server has moved up to PHP 5.3, and you're still running old code that's incompatible with this PHP version. Go searching on "eregi" and you'll find plenty of discussion on it. Once that's fixed, the "Cannot modify header information" error will go away all by itself.

#12 ogwinilo

  • Community Member
  • 150 posts
  • Real Name:Felix
  • Gender:Male

Posted 29 February 2012, 04:40

@MrPhil

thanks MrPhil, will look it up

#13 arkisaeo

  • Community Member
  • 61 posts
  • Real Name:mituka aufaey

Posted 14 May 2012, 18:11

Having similar trouble (even after using this contrib).

Here's the message:

Warning: Cannot modify header information - headers already sent by (output started at *******/admin/products_attributes.php:18) in *******/admin/includes/functions/general.php on line 34


Here is what I got from using the contrib:

O/S = Linux.
admin/products_attributes.php has 1047 lines.
The PHP start tag is on line 1.
The PHP end tag is on line 1047.
Contents from start of file to the PHP start tag:

<?php[0A]

-------------------------
Contents from PHP end tag to end of file:

?>

-------------------------
Extended contents of the requested line [18] are:

<script[20]type="text/javascript">[0A]

-------------------------
Raw contents of the requested line [18] are:



This is what's on line 34 of the admin/includes/functions/general.php file:

header('Location: ' . $url);


#14 germ

  • Community Member
  • 13,586 posts
  • Real Name:Jim
  • Gender:Male
  • Location:USA (GMT-6)

Posted 14 May 2012, 20:38

Post the first 25 lines of *******/admin/products_attributes.php
If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

"Headers already sent" - The definitive help

"Cannot redeclare ..." - How to find/fix it

SSL Implementation Help

Like this post? "Like" it again over there >