Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Url变量和重定向_Php_Url_Variables_Redirect - Fatal编程技术网

Php 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

当我的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/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()
。代码越少越好!