PHP 使用 XAMPP 8..1.1 重现警告"Cannot modify header information - headers already sent by (output started



我使用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上使用相同的设置,我甚至没有收到警告。

非常感谢你的帮助。

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

相关内容

最新更新