Php Url变量和重定向
当我的url有一个变量时,比如:Php Url变量和重定向,php,url,variables,redirect,Php,Url,Variables,Redirect,当我的url有一个变量时,比如:www.mysite.com/anives.php?pet=dogs我会检查: if (!isset($_GET['pet']) || empty($_GET['pet']) || ($pet_true === false)){ header('Location: error.php'); exit(); } echo 'list of dogs'; 当pet未设置或为空或为假时,我会得到重定向,所以它可以工作 但我想添加第二个变量:www.mysite.com
www.mysite.com/anives.php?pet=dogs
我会检查:
if (!isset($_GET['pet']) || empty($_GET['pet']) || ($pet_true === false)){
header('Location: error.php');
exit();
} echo 'list of dogs';
当pet未设置或为空或为假时,我会得到重定向,所以它可以工作
但我想添加第二个变量:www.mysite.com/anives.php?pet=dogs&breed=collie
并进行检查:
if (!isset($_GET['pet']) || empty($_GET['pet']) || ($pet_true === false)){
header('Location: error.php');
exit();
} echo 'list of dogs';
- 若品种未设置或为空或为假:重定向至错误页面
- 如果url为:
:重定向到错误页面?pet=dogs&madeup
if (!isset($_GET['breed']) || empty($_GET['breed']) || ($breed_true === false)){
header('Location: error.php');
exit();
} else {
echo 'Collie info';
}
但当url是正确的时,我会得到重定向,因为没有设置品种
我能想到的唯一解决办法是什么都不回应:
if (!isset($_GET['breed']) || empty($_GET['breed']) || ($breed_true === false)){
echo '';
} else {
echo 'Collie info';
}
但是现在在
?pet=dogs&
用户可以键入他想要的任何内容,我不知道是否安全,我认为重定向到错误页面会更好,但是有可能吗???什么是$pet\u true
和$bride\u true
?实际问题是什么?那么如果bride
没有设置,你希望发生什么?empty()
本质上是的简明等价物!isset($var)|$var==false
,因此如果您使用的是empty()
,则无需使用isset()
。代码越少越好!