使用$ _GET从URL参数中获取任何内容

时间:2015-08-12 15:08:32

标签: php get key-value

我有这个网址:/admin.php?op = admin& action = delete& link = / showitems.php?id = 8745

我还需要获取op参数以及动作和链接参数。如果我编写这样的代码:

$op = $_GET['op'];
echo $op; //the output is admin

$action = $_GET['action'];
echo $action; //The output is nothing; 

$link = $_GET['link'];
echo $link; //The output is nothing;

//IF I want to sanitize the data same happens with

$op = filter_input(INPUT_GET,"op",FILTER_SANITIZE_STRING); 
echo $op; //the output is admin
$action = filter_input(INPUT_GET,"action",FILTER_SANITIZE_STRING);
echo $action; //the output is nothing
$link = filter_input(INPUT_GET,"link",FILTER_SANITIZE_STRING);
echo $link; //the output is nothing

//If I go for the whole array of parameters there they are.
foreach($_GET as $key=>$value){
    echo $key . " : " . $value; //The output is op : admin;action : deleteamp;link : /showitems.php?id=8745
}

当我尝试直接获取第二个或第三个参数(如本案例中的动作和链接)时会出现什么问题?谢谢你的任何建议。问候。

0 个答案:

没有答案