【问题标题】:PHP reproduce warning "Cannot modify header information - headers already sent by (output started at... " with XAMPP 8..1.1PHP 使用 XAMPP 8..1.1 重现警告“无法修改标头信息 - 标头已由(输出开始于...)发送”
【发布时间】:2022-01-04 08:30:14
【问题描述】:

我使用 XAMPP 8.1.1 作为开发者。环境。在 php.ini 中设置:error_reporting = E_ALL

使用此代码,我期待警告:“无法修改标头信息 - 标头已由...发送”

<?php
echo 'It works!<br>';
//Expected Warning "Cannot modify header information - headers already sent by"
header ('Content-Type: text/html; charset=utf-8');

echo '<br>...not!';
?>

如果我将此函数称为我的 ISP,我会收到警告,但不会在我的 XAMPP 安装中。我应该改变什么,我也会在我的 XAMPP 安装中收到这个警告?我无法访问我的 ISP 的 php.ini 文件来比较设置,我发现的只是错误报告不那么严格,但是在我的 XAMPP 上使用相同的设置,我什至没有得到警告。

非常感谢您的帮助。

【问题讨论】:

标签: php apache xampp


【解决方案1】:

您的 ISP 已禁用输出缓冲。在您的 XAMPP 安装中,它已启用。在发送标头之前输出内容不会产生警告,除非内容长度超过配置的output_buffering 值(默认为 4096)。 https://www.php.net/manual/en/outcontrol.configuration.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-09
    • 1970-01-01
    • 2013-11-24
    • 2017-11-05
    • 1970-01-01
    • 2011-01-15
    相关资源
    最近更新 更多