我正在尝试确定在检查超全局初始化时是否需要清理。在我的情况下,$ _GET ['reply']变量并不意味着用于输入数据库的用户,但我可以使用它来链接数据库上的页面。与此http://******.com/forum.php?reply=123
类似,但forum.php
需要多个变量,但一次只能使用一个变量。它需要$_GET['post']
,$_GET['tag']
或$_GET['search'][]
。我创建了三种检查初始化的方法,并希望确定哪种方法在速度和安全性方面最适合这种情况。
方法#1:
if(isset($_GET['reply'])){
$reply = filter_input(INPUT_GET, "reply");
//display reply query
}
elseif(isset($_GET['post'])){
$post = filter_input(INPUT_GET, "post");
//display post query
}
elseif(isset($_GET['tag'])){
$tag = filter_input(INPUT_GET, "tag");
//display tag query
}
elseif(isset($_GET['search'])){
$search = filter_input(INPUT_GET, "search");
//display search query
//$_GET['search'] is an array and I haven't figured out how properly filter it.
}
else{
//display default query;
}
方法#2:
if(filter_input(INPUT_GET, "reply")){
$reply = filter_input(INPUT_GET, "reply");
//display reply query
}
elseif(filter_input(INPUT_GET, "post")){
$post = filter_input(INPUT_GET, "post");
//display post query
}
elseif(filter_input(INPUT_GET, "tag")){
$tag = filter_input(INPUT_GET, "tag");
//display tag query
}
elseif(filter_input(INPUT_GET, "search")){
$search = filter_input(INPUT_GET, "search");
//display search query
//$_GET['search'] is an array and I haven't figured out how properly filter it.
}
else{
//display default query;
}
方法#3:
$reply = filter_input(INPUT_GET, "reply");
$post = filter_input(INPUT_GET, "post");
$tag = filter_input(INPUT_GET, "tag");
$search = filter_input(INPUT_GET, "search");
if($reply){ /* display reply query */ }
elseif($post){ /* display post query */ }
elseif($tag){ /* display tag query */ }
elseif($search){ /* display search query */ }
else{ /* display default query */ }