我似乎一直在收到此错误:无法修改标头信息-标头已经由...发送。
我不明白我在做什么错。头文件只是一个普通的头文件... view code
奇怪的是,它在wampserver上没有任何错误,但在托管服务器上却有此错误。
我不得不检查空白和奇怪的输出,但是找不到任何东西?
<?php
require 'header.php';
require 'includes/dbh.inc.php';
// Search system
if (isset($_POST['submit'])){
$aMust = $_POST['must'];
$aOptional = $_POST['optional'];
$category = $_POST['category'];
if ($_POST['category'] == "Breedables"){
header("Location: categories/breedables.php?must=".$aMust."&optional=".$aOptional);
exit();
} else if ($_POST['category'] == "Jobs"){
header("Location: categories/jobs.php?must=".$aMust."&optional=".$aOptional);
exit();
}
}
答案 0 :(得分:0)
您收到此错误,因为调用标头功能时某些内容已经发送回浏览器。并且仅在将任何内容发送回浏览器之前才可以设置标题,因为必须在发送任何内容之前发送标题。
如果在调用标头之前确实找不到发送到浏览器的内容,则可以output-buffers:
<?php
ob_start();
// some php code
header('My custom header');
$ob_content = ob_get_contents();
ob_end_clean();
echo($ob_content);
// Or as an alternative to the three lines above use: ob_end_flush();
// other/more code