Ozz*_*zzC 0 php error-handling function output
我试图开发一个搜索系统,我有一个问题..
我在同一目录中有一个index.php文件和一个search.php文件,我希望当用户在搜索字段中写入并提交时我想转到我的搜索页面.
但是我不明白发生了什么,因为我转到这个页面:localhost/project/tpl/search /但是一切都是白色的,我没有错误,但没有显示我的"search.php"文件的背景!
我尝试过:header('Location: http://localhost/project/tpl/search/');但我有同样的问题!
那里有人知道可能会发生什么?
<?php
if(isset($_POST['search']))
{
$search = $_POST['s'];
$search = setUri($search);
header('http://localhost/project/tpl/search/');
echo $search;
}
?>
<form name="search" method="post" >
<input id="test" type="search" name="s" placeholder="Search..." required="required" onfocus="if(this.placeholder == 'Search...') {this.placeholder=''}" onblur="if(this.placeholder == ''){this.placeholder ='Search...'}" />
<input type="submit" class="expand" name="search"></button>
</form>
Run Code Online (Sandbox Code Playgroud)
我的项目文件夹在htdocs中,我的项目文件夹是这样的:

然后search.php在tpl文件夹中,如下所示:

您忘记了函数中的location关键字header().
一定是..
header("location:http://localhost/project/tpl/search/");
Run Code Online (Sandbox Code Playgroud)
警告:此外,您正试图在echo内容之后header()无法看到内容.
在通话结束后删除echo并添加一个..exitheader()
if(isset($_POST['search']))
{
$search = $_POST['s'];
$search = setUri($search);
header('location : http://localhost/project/tpl/search/');
//echo $search;
exit;
}
Run Code Online (Sandbox Code Playgroud)