【发布时间】:2014-03-07 09:02:13
【问题描述】:
我意识到我的舞台服务器与我的 localhost 不匹配。
我在发送两次的标头上犯了一些错误。不幸的是,在我的本地主机上一切正常,但在舞台服务器上我收到了正确的警告:
“警告:无法修改标头信息 - 标头已由”...
这是我的 Apache 上的一些配置调整吗?
Stage 在 GoDaddy/linux (Apache/version?) 上运行,PHP 版本 5.4.19
本地主机为 Apache/2.4.6,php 5.5.3-1ubuntu2.1
编辑:
一些示例代码,希望能澄清......
在我的本地主机上,页面每次都被重定向而没有错误,输出文本“页面重定向完成!”每次刷新时都会显示。
在舞台上,报这个错误“Warning: Cannot modify header information - headers already sent by”,输出文本“Page redirect done!”根本不显示。
<?php
ini_set("display_errors", true);
error_reporting(E_ALL);
if (!isset($_SESSION)) {
session_start();
}
?>
<html><body><h1>It works!</h1>
</body></html>
<?php
if (isset($_SESSION['redirect'])) {
unset($_SESSION['redirect']);
echo "Page redirect done!<br><br>";
echo "Session redirect is now unset, please update one more time to be sure!";
} else {
$_SESSION['redirect'] = "1";
header("Location: index.php");
}
?>
谢谢!
【问题讨论】:
-
我找到了原因。我只是删除了我的 php.ini 中的 output_buffering,我得到了与舞台服务器上相同的行为。这个答案中关于标题的一个很好的解释stackoverflow.com/questions/8028957/…
标签: php apache http-headers