1

Hi I have a php file that is empty and the only line of code in there is

<?php session_start(); ?>

No html mark-up or any php code besides the code above.

On localhost it doesn't trigger an error, but when it's on the server and I visit the page, a new line is printed on the error log that says

[25-Apr-2016 05:43:34 UTC] PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at path/to/file.php:1) in /path/to/file.php on line 1

The server is running apache and php 5.6 if that's relevant, I've also tried deleting the .htacces file just in case that is what's causing the problem but still no luck.

Can anyone point me in the right direction to see what may be causing the issue? Thanks!

Justin Mercado
  • 187
  • 1
  • 8
  • Are you accessing this PHP file directly? Is there an included PHP script somewhere that's calling `session_start` after any content is output? – Bitwise Creative Apr 25 '16 at 05:53
  • Yes. I'm accessing the page like "domain.com/file.php". There is an included session_start() somewhere on different pages but not on the current page – Justin Mercado Apr 25 '16 at 05:55
  • I assume it's on line 1 (no whitespace above). I found this (http://serverfault.com/questions/618316/warning-session-start-cannot-send-session-cache-limiter-headers-already-sent) who never seemed to get a verified answer. Maybe try splitting your code on three lines: 1. `` – Bitwise Creative Apr 25 '16 at 06:00
  • Error changed to "... headers already sent (output started at path/to/file.php:1) in /path/to/file.php on line 2". output started at is still on the same line. But an error was still printed on the error_log – Justin Mercado Apr 25 '16 at 06:05
  • Ahh, weird. Well, thanks for testing my idea. I was thinking maybe PHP was struggling with `session_start` and `?>` on the same line. – Bitwise Creative Apr 25 '16 at 06:07
  • 1
    Thanks bitwise but Umair solved my problem, thanks for your input! – Justin Mercado Apr 25 '16 at 06:09

1 Answers1

1

Problem : Sometimes there are invisible characters inside your code file.

Solution : So simply for now if want to fix the error so here is the quick way to do it : I am sure you must be using some sort of Code Editor just simply save your php file with encoding as "UTF-8 With BOM" and then upload the saved file to your site and then access your file and you will have no problem..!

Screenshot For Better Guidance : enter image description here

Reference URL :

How to fix "Headers already sent" error in PHP

If that doesn't solve your problem so then use this solution :

  1. Make sure there is absolutely no whitespace before <?php
  2. Put session_start() before ob_start() instead of after it.
  3. If that fails, try commenting out the session_start() as one of your includes might already be starting the session, like so: /** session_start(); **/
Community
  • 1
  • 1
Umair Shah
  • 2,305
  • 2
  • 25
  • 50
  • Wow, thanks! That solved my problem. This is the first time I've read about this, what is this problem called specifically so that I could research more about it? The save with encoding solved my problem to be precise – Justin Mercado Apr 25 '16 at 06:08
  • @JustinMercado : answer updated for reference URL & You are welcome.No Problem at all..Don't hesitate in asking for more help if you feel the need..! – Umair Shah Apr 25 '16 at 07:07