0

It's a header already sent question but the issue I have is that I have a script which I run locally (easyPHP on Win) and on my live server (LAMP).

This works fine on both and I do not get the header error.

Now I have a client who runs it on his server and he's getting the header error.

I'm pretty sure the issue is one of the files (I've just sent him one with no break lines after "?>" - that can be an issue right?) but I have no idea why he's getting the error but I'm not - even with the whitespace after "?>" (yes, my error reporting is on)

Is there something other than white spaces that can cause this error?

Quick edit, having read the question linked below

First error:

<b>Warning</b>:  session_regenerate_id() [<a href='function.session-regenerate-id'>function.session-regenerate-id</a>]: Cannot regenerate session id - headers already sent in <b>bla bla bla/includes/lightwork_session.php</b> on line <b>33</b><br />

Line 33 in "lightwork_session" is: I don't think this is the issue

public static function sessionStart(){
//regenerate the session id to prevent session fixation
session_regenerate_id(true); //hello, I'm line 33
session_start(); //hello again, I'm line 34 in

}

Next batch of errors:

  <b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at bla bla blaconfig/config_global.php:167) in <b>bla bla bla/includes/lightwork_session.php</b> on line <b>34</b><br />
<br />

<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at bla bla bla/config/config_global.php:167) in <b>bla bla bla/includes/lightwork_session.php</b> on line <b>34</b><br />

Okay line 167 in config_global.php is white space just after "?>"

I've sent him a file without that whitespace but being on the other side of the world I'll find out tomorrow how that works out for him. But I'm stumped as to why he gets the error and I do not?

Theraot
  • 31,890
  • 5
  • 57
  • 86
KB.
  • 3,549
  • 4
  • 23
  • 29
  • Post some code, would be more clear and we could try to look for different possibilities! – Bono Apr 03 '12 at 11:15
  • 2
    possible duplicate of [Headers already sent by PHP](http://stackoverflow.com/questions/8028957/headers-already-sent-by-php) – mario Apr 03 '12 at 11:15
  • It is almost always whitespace or text of some kind. Show come code and we could help! – ChrisK Apr 03 '12 at 11:17
  • Just for those reading - it was white space - of course. But I never found out why I was not getting the error my end. – KB. Apr 04 '12 at 21:36

3 Answers3

2

In addition to @davidethell, I'd like to add that it's also possible the error is caused by line break types or Unicode signatures. This is an option in a lot of IDE's and other editors (see the 'New Document' and 'Code Format' section in Dreamweaver for example). To be safe, always go for Unix styled line break types (LF instead of CR LF) and don't include the Unicode signature (BOM).

Also, a general tip when working with large PHP files: you don't have to include the closing ?> tag. CodeIgniter for example adopted this practice, they just "close" their files with a comment, this prevents accidental whitespace after the closing php tag.

Bram
  • 1,112
  • 1
  • 9
  • 23
  • Thanks for the ?> tip. I was using Komodo Edit - he was using DWeaver and I told him to use jEdit just in case it him editing the file. – KB. Apr 03 '12 at 11:38
1

White space after the closing tag is one problem, but another common reason this happens is due to PHP warnings and notices being turned to a higher reporting level on his server. If you have any warnings or notices from PHP that get printed out this will cause the headers warning. You should turn off notices on his server using:

error_reporting(E_ERROR | E_WARNING | E_PARSE);

or to have only errors:

error_reporting(E_ERROR);

I would recommend leaving E_WARNING on and fixing the issues that are reported, but at least it will tell you if that is the problem.

davidethell
  • 11,708
  • 6
  • 43
  • 63
  • What is the highest level I can set it to - to try to re-create this problem (or test if this may be the issue) – KB. Apr 03 '12 at 11:39
  • Mines already set to E_ALL | E_STRICT so I should be getting the max error reporting? - but Grrr! – KB. Apr 03 '12 at 11:42
0

Some cases would be as follows:

  1. Whitespace before the opening php tag <?php
  2. Sending something to the browser before using session_start, header, setcookie etc..
  3. UTF BOM (byte order mark) problem..

If you want a quick fix....take a look at ob_start() in PHP....although using ob_start to suppress errors of this kind is a stopgap arrangement.

Hope this helps..

web-nomad
  • 6,003
  • 3
  • 34
  • 49
  • Wouldn't recommend output buffering as a fix, as @Pushpesh says: it's a stopgap fix that doesn't actually do anything about the problem. – Bram Apr 03 '12 at 11:42