我已经添加了一些服务器端验证到我的一个网页上的下拉框,当我做了网页不会工作了。我添加的代码如下:混淆为什么代码只能使用ob_start();
$show_form = true;
if (isset($_POST['submit'])) {
//All of the server side validations
$validator = new FormValidator();
$validator->addValidation("hospital_name","dontselect=000","No facility was chosen");
if ($validator->ValidateForm()) {
// All the variables from the submission form
$userid = $_SESSION['user_id'];
$hosp = $_POST['hospital_name'];
header('Location: ../site_hospital' . $hosp . '/hospital_submitform.php?usr=' . $userid . '&&hosp=' . $hosp);
exit;
$show_form = false;
} else {
echo "<B style='color:red;'>The following errors occurred:</B>";
$error_hash = $validator->GetErrors();
foreach ($error_hash as $inpname => $inp_err) {
echo "<p style='color:red;'>$inp_err</p>\n";
}
}}
if (true == $show_form) {
通过纯粹的机会,我添加了ob_start();作为我调试页面开始的一部分,突然间我的代码正常工作,但我不知道为什么,我希望社区能够抛出一个有根据的猜测。当代码停止工作时,它不会执行上面的页眉命令,当我添加ob_start()时,页面只会刷新并且不会更改位置。到页面顶部按照计划重定向页面。所以总的问题是,为什么页面不直接使用header命令而没有ob_start?我确信更多的细节和代码对于明确的答案是必要的,但我希望有人遇到过这种情况,或者有一个有教养的猜测,可能会导致我自己的答案。感谢您的任何见解。
[Headers already already sent by PHP](http://stackoverflow.com/questions/8028957/headers-already-sent-by-php) – mario 2012-03-11 23:33:35