会话在空页上启动会导致错误;session_start():无法发送会话缓存限制器 [英] Session start on an empty page causes an error; session_start(): Cannot send session cache limiter

查看:51
本文介绍了会话在空页上启动会导致错误;session_start():无法发送会话缓存限制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个空的 php 文件,其中唯一的一行代码是

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

<?php session_start(); ?>

除上述代码外,没有任何 html 标记或任何 php 代码.

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

[2016 年 4 月 25 日 05:43:34 UTC] PHP 警告:session_start():无法发送会话缓存限制器 -/path/中的标头已发送(输出从 path/to/file.php:1 开始)to/file.php 第 1 行

[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

如果相关,服务器正在运行 apache 和 php 5.6,我也尝试删除 .htacces 文件,以防万一这是导致问题的原因,但仍然没有运气.

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!

推荐答案

问题: 有时代码文件中存在不可见字符.

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

解决方案:所以现在很简单,如果想修复错误,那么这里是快速的方法:我确定您必须使用某种代码编辑器,只需将编码为带有 BOM 的 UTF-8"的 php 文件保存,然后将保存的文件上传到您的站点,然后访问您的文件,您就没有问题了..!

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..!

屏幕截图以获得更好的指导:

参考网址:

如何修复标题已发送"PHP中的错误

如果这不能解决您的问题,那么请使用此解决方案:

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

  1. 确保
  2. 之前绝对没有空格
  3. session_start() 放在 ob_start() 之前而不是之后.
  4. 如果失败,请尝试将 session_start() 作为您的包含可能已经开始会话,如下所示: /** session_start();**/
  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(); **/

这篇关于会话在空页上启动会导致错误;session_start():无法发送会话缓存限制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆