【问题标题】:Having an error with my PHP code (Cannot send cookie cache, session cache limiter)我的 PHP 代码出错(无法发送 cookie 缓存、会话缓存限制器)
【发布时间】:2013-05-31 23:27:12
【问题描述】:

我正在尝试创建一个注册和登录页面。尝试将代码上传到我们的服务器时,会产生两个错误:

警告:session_start() [function.session-start]:无法发送会话 cookie - 标头已由 /Applications/ 中的(输出开始于 /Applications/XAMPP/xamppfiles/htdocs/tisun_search/index.php:52)发送XAMPP/xamppfiles/htdocs/tisun_search/functions.php 在第 2 行

警告:session_start() [function.session-start]:无法发送会话缓存限制器 - 标头已发送(输出开始于 /Applications/XAMPP/xamppfiles/htdocs/tisun_search/index.php:52)在 /Applications/ XAMPP/xamppfiles/htdocs/tisun_search/functions.php 在第 2 行

我已经尝试检查 functions.php 文件中的问题,没有空格,也没有任何可见的错误。

我想知道是否有人会碰巧知道发生此错误的任何其他原因以及解决此错误的解决方案。

下面是我的functions.php代码的开头(没有php标签)。

session_start(); 

function loggedin() 
{
if(isset($_SESSION['user_id']) && !empty($_SESSION['user_id']))
{
return true;
    }
    else
    {
    return false;
    }
}

下面的代码显示了错误发生的位置

【问题讨论】:

    标签: php session caching cookies xampp


    【解决方案1】:

    解决此问题的唯一方法是遍历所有包含并检查它们是否正在执行某些输出(echo、printf),或者最常见的是,在纯包含(类等)中,您在最终包含空格和 NL关闭?>:

    ....
    } // end of class xyz
    
    /*
     * some comments
     */
    ············¶
    ?>·················¶
    ¶
    ¶
    ¶
    ¶
    <--- EOF
    

    NL 可能不是问题,但尾随空格和 NL。使用 Eclipse 后,您可以将其配置为自动删除这些工件。

    【讨论】:

    • 嗯。错误消息告诉您输出发生的确切位置(output started at /Applications/XAMPP/xamppfiles/htdocs/tisun_search/index.php:52) (即文件 /Applications/XAMPP/xamppfiles/htdocs/tisun_search/index.php 的第 52 行)
    • 问题实际上是关于 session_start 发生的时间,应该在被调用脚本的最开始,而不是在脚本执行中很远的包含文件中
    猜你喜欢
    • 1970-01-01
    • 2013-06-08
    • 2016-12-14
    • 2014-06-04
    • 2017-10-19
    • 2012-02-07
    • 1970-01-01
    相关资源
    最近更新 更多