问题
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!
回答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 :
Reference URL :
How to fix "Headers already sent" error in PHP
If that doesn't solve your problem so then use this solution :
- Make sure there is absolutely no whitespace before
<?php
- Put
session_start()
beforeob_start()
instead of after it. - If that fails, try commenting out the
session_start()
as one of your includes might already be starting the session, like so:/** session_start(); **/
来源:https://stackoverflow.com/questions/36832909/session-start-on-an-empty-page-causes-an-error-session-start-cannot-send-ses