-1

Got a strange one. Im working on a system and the login breaks when i move it from the development server to the live one, giving this error:

[21-Feb-2017 16:55:40 Europe/London] PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/xxx/public_html/olympus/index.php:12) in /home/xxx/public_html/olympus/classes/login.php on line 28

It works fine if i move the session start directly to the top of the file. But where im confused, it works with no problems on the development server?

They are both cpanel servers, only major difference on the development server is its running cloudlinux. Any idea if any php setting would be causing this?

Iqbal Rizky
  • 352
  • 3
  • 16
Jargen
  • 13
  • 4
  • 2
    as it says: "output started at /home/xxx/public_html/olympus/index.php:12" –  Feb 22 '17 at 23:32
  • The files are exactly the same as on the development server. Which works with no issues. – Jargen Feb 22 '17 at 23:37
  • the files? you know we cant see them right? –  Feb 22 '17 at 23:37
  • @patito `?>` tags are optional at the end of a file - and actually it is much better to skip them as you don't accidentally add whitespace after them (which is a common cause of this type of error) – Theo Feb 22 '17 at 23:43
  • Found the difference between the servers. output buffering was set to off, changing it to 4096 has resolved it. Thanks for the help. – Jargen Feb 22 '17 at 23:44

1 Answers1

0

This means something is writing output before you call session_start - it is even telling you where (/home/xxx/public_html/olympus/index.php on line 12)

Without seeing that file its hard to know exactly what is outputing but other than the obvious output functions of echo/print etc. a common cause is newlines/whitespace before your opening php tags (or after your closing tags - which are optional and better to miss out altogether at the end of a file)

Theo
  • 1,608
  • 1
  • 9
  • 16
  • The files are exactly the same as on the development server. Which works with no issues. – Jargen Feb 22 '17 at 23:37
  • Have you verified this by running an md5 function or something. Its a common mistake to assume they are the same without realising something is different (line endings etc.) Otherwise without seeing the content of at least index.php (and ideally login.php) it is very hard to help. – Theo Feb 22 '17 at 23:42
  • Found the difference between the servers. output buffering was set to off, changing it to 4096 has resolved it. Thanks for the help. – Jargen Feb 22 '17 at 23:44
  • This doesn't sound like a fix, it may explain the difference in behaviour, but **relying on output buffering to delay the sending of accidental output, is just covering the problem up** - I strongly encourage you to turn it back off, find the output and either get rid of it (if it is incorrect), or move your session_start before the output if it is in fact valid output – Theo Feb 22 '17 at 23:48