tags:

views:

24

answers:

5

I have my site live in which i echoed few strings for testing, so it displayed me those test strings but along with the warning message

Warning: Cannot modify header information - headers already sent by (output started at /home/companyfolder/public_html/mycart.php:117) in /home/companyfolder/public_html/includes/functions/general.php on line 50

But at the same time i do not get this error any where in my local machine so i want to know is there any difference in display of header information related to servers?

A: 

You have the same issue in both places, just different error reporting levels. You can configure this in your php.ini file or at runtime with error_reporting()

jasonbar
+1  A: 

Because of output buffering

And not a single one, who volunteered to share their knowledge about error handling, mentioned a way more likely reason - display_errors turned off, as it on the live site ought to be.

Of course it should be. To

  • not to scare users with strange messages
  • not to reveal vital info of your application to possible attacker. nor to supply them with any feedback.
  • inform a programmer of all errors occurred, by turning log_errors setting on

Thus, on a development site

display_errors = on
log_errors = off 

on a live site

display_errors = off
log_errors = on

while error reporting level should remain the same - E_ALL or better

Col. Shrapnel
Is it good practice to make display_errors turned off on live site?
OM The Eternity
@OM it's the only possible choice. An obligatory rule. See an updated answer for fancy formatted explanation.
Col. Shrapnel
While display_errors() most certainly should be turned off on a production server, "test" and "local machine" both imply development environments where you would certainly *not* want display_errors() disabled.
jasonbar
+1 I like the way you reply, I call this "Reply in Sarcastic Way" :-)
OM The Eternity
A: 

This error is pretty general, but basically what is happening is what it says. You're including mycart.php in a page and on like 117 it starts outputting HTML (or something client-side), once this starts happening you can't modify any of the header information (ex. a redirect). Like jason said though, the reason the error isn't showing up is the error_reporting setting.

EDIT: You can solve some of these problems by using ob_start() and then ob_end_flush() after you've done your header modifying.

David Weitz
Do they have any problem?
Col. Shrapnel
And if they have one, it must be solved with proper application design, not a dirty patch. Output buffering is a tool, for it's own purpose, not to conceal holes in application design. Good planned application will never output anything before headers being sent.
Col. Shrapnel
A: 

Your other server configuration might have output buffering turned on in the php.ini file.

TheMagician
A: 

The server has this in php.ini

  error_reporting(E_ALL);

if you just want errors then use

  error_reporting(E_ERROR | E_PARSE);
nobody wants error_reporting at any level other than E_ALL or E_STRICT
Col. Shrapnel