0

i have uploaded my project on the server but when i try to run it it shows this warning. However on my local machine every thing is working just perfect what could be the problem.

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/prosyst2/public_html/sms/index.php:1) in /home/prosyst2/public_html/sms/auth.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at /home/prosyst2/public_html/sms/index.php:1) in /home/prosyst2/public_html/sms/auth.php on line 8

Community
  • 1
  • 1
Shaffic Muza
  • 51
  • 1
  • 1

2 Answers2

0

You can't set session/cookie after you echo'd something or generated some output.

You can use ob_start(); at the beginning of the file and echo ob_get_clean(); at the end to buffer the output.

x13
  • 2,179
  • 1
  • 11
  • 27
0

Your local php installation does not report warnings correctly, set it to report E_ALL, which is errors, warnings, notices etc, and the other way on the server.

When it comes to your specific problem, you have output before your session_start(); call, this could be html or anything that writes to the output buffer, or incase session_start(); is on the top of the page, possibly a BOM character.

How to fix:
Never do any output before sending headers (header(...), session_start() etc) and this wont happen.
Always report all errors and warnings etc on a development installation, so you know whats wrong.

Jite
  • 5,761
  • 2
  • 23
  • 37
  • I almost always use `display_errors: 1` so that any errors appear on the page, this also is output after which you cannot access the header. So be careful when using error logging because it may work against you. – x13 Oct 03 '15 at 14:50
  • Well, the reason you have error logging set to show all is so that you can fix them before deploying to production... So they never work against you if you fix them, right away. – Jite Oct 03 '15 at 15:06
  • I had multiple examples of working code that only raised some notices but was spoiled by the display errors – x13 Oct 03 '15 at 15:07
  • Well yes, but if it shows a notice, the thing the notice tells you should be fixed, not ignored. – Jite Oct 03 '15 at 15:08
  • I once had mcrypt telling me i had not supplied an IV and that i should, but u decided i would make sure everything works before finetuning this since mcrypt still did its job without the IV. The display errors killed my page. – x13 Oct 03 '15 at 15:10