我想通过更改参数值并按地址中的回车键来搜索结果。 当我在主页上搜索时,我使用这种形式在网址中传递搜索关键字
eg:->http://localhost/mydeals/searchListing.php?sRes=g
现在,当我在 searchListing.php 上时,我想将 sRes 的参数更改为 p ,之后当我在地址栏中按 Enter 键时,我会得到 $_GET 中的值,那么我如何搜索它。
eg:->http://localhost/mydeals/searchListing.php?sRes=p
我在配置文件中编写的 php 代码是。
if(isset($_POST['search2']))
{
if(trim($_POST['location2'])!="" && $_GET['sRes'] =="")
{
$_SESSION['dirLocation2'] = trim($_POST['location2']);
header("location:".THIS_DOMAIN."searchListing.php?sRes=".$_SESSION['dirLocation2']);
}else if($_GET['sRes'] !=""){
$_SESSION['dirLocation2'] = trim($_GET['sRes']);
header("location:".THIS_DOMAIN."searchListing.php?sRes=".$_SESSION['dirLocation2']);
}else{
header("location:".THIS_DOMAIN."index.php");
}
}
if (empty($_GET["sRes"])) {
header("location:".THIS_DOMAIN."index.php");
} else{
$_SESSION['dirLocation2'] = trim($_GET['sRes']);
header("location:".THIS_DOMAIN."searchListing.php?sRes=".$_SESSION['dirLocation2']);
}
最佳答案
您可以通过检查 url 参数来做到这一点,例如;
<?php
if (empty($_GET["sRes"])) {
header("Location: index.php");
} else {
$sResValue = $_GET["sRes"]; // p, or s
// Do your search here
}
关于php - 如何通过更改 url 参数并在 php 中按 Enter 键来搜索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23670366/