Session start on an empty page causes an error; session_start(): Cannot send session cache limiter

左心房为你撑大大i 提交于 2021-01-29 04:32:03

问题


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 :

  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(); **/


来源:https://stackoverflow.com/questions/36832909/session-start-on-an-empty-page-causes-an-error-session-start-cannot-send-ses

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!