“标题已经发送”,但是“没有输出开始...”

发布于 2025-02-06 14:07:35 字数 374 浏览 0 评论 0原文

我得到php警告:session_start():在已经发送标题后无法启动会话...错误消息。

我读了许多类似的问题,但是就我而言,上述错误消息不包含(输出启动在/some/file.php:12) part,没有它,我无法解决问题。

如何在... 零件上添加到错误消息中的输出?

我通过NGINX使用php-fpm的PHP 8.0,以下概念证明WordPress插件触发了错误:

add_action('init', function() {
    session_start();
});

没有其他插件激活,我正在使用库存二十二十一名主题。

I get the PHP Warning: session_start(): Session cannot be started after headers have already been sent in ... error message.

I read many similar questions, but in my case, the above error message doesn't contain the (output started at /some/file.php:12) part, and without it, I'm unable to resolve the issue.

How can I get the output started at ... part added to the error message?

I use PHP 8.0 with PHP-FPM via NGINX, and the following proof-of-concept WordPress plugin triggers the error:

add_action('init', function() {
    session_start();
});

There are no other plugins activated, and I'm using the stock Twenty Twenty-Two theme.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘虞初梦 2025-02-13 14:07:35

其他地方已经输出数据,因此Session_start()导致了该错误。

尝试在该插件部分代码上替换Session_start()。

if(!isset($_SESSION)) {
     session_start();
}

Other place already output the data so session_start() caused that error.

Try replace session_start() with this one on that plugin section code.

if(!isset($_SESSION)) {
     session_start();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文