Header 位置不工作
Header Location is not working
我已经搜索了一段时间,似乎找不到解决我问题的方法。希望大家能帮帮我。
这是我的代码:
<?php
ob_start();
if(isset($_POST['searchstring'])){
include ("connect.php");
$queried = $_POST['searchstring'];
$queried = trim($queried);
$patterns = array("/\s+/", "/\s([?.!])/");
$replacer = array("+","");
$queried = preg_replace( $patterns, $replacer, $queried );
header("Location: index.php?page=search&q=".$queried."");
}
else {
header('Location: index.php');
}
exit();
?>
我什至尝试只使用以下代码:
<?php header('Location: index.php'); ?>
这也不行。这很奇怪,因为我已经使用 header 位置一百万次了。它在本地主机上 100% 正常工作,但在服务器上它失败了——它只显示一个空白页面。有什么想法吗?
- 使用完整的 url 而不是 index.php。
- 尝试 url 喜欢 [http://example.com/index.php]
好的。我发现了错误。显然我以某种方式用 BOM 保存了我的文档,这使得代码不知何故无效。
谢谢大家的帮助。
我已经搜索了一段时间,似乎找不到解决我问题的方法。希望大家能帮帮我。
这是我的代码:
<?php
ob_start();
if(isset($_POST['searchstring'])){
include ("connect.php");
$queried = $_POST['searchstring'];
$queried = trim($queried);
$patterns = array("/\s+/", "/\s([?.!])/");
$replacer = array("+","");
$queried = preg_replace( $patterns, $replacer, $queried );
header("Location: index.php?page=search&q=".$queried."");
}
else {
header('Location: index.php');
}
exit();
?>
我什至尝试只使用以下代码:
<?php header('Location: index.php'); ?>
这也不行。这很奇怪,因为我已经使用 header 位置一百万次了。它在本地主机上 100% 正常工作,但在服务器上它失败了——它只显示一个空白页面。有什么想法吗?
- 使用完整的 url 而不是 index.php。
- 尝试 url 喜欢 [http://example.com/index.php]
好的。我发现了错误。显然我以某种方式用 BOM 保存了我的文档,这使得代码不知何故无效。
谢谢大家的帮助。