Get all possible $_GET parameters from URL

时间:2018-02-21 11:49:35

标签: php url get

I have link to a website that runs a php code with the following variable:
http://www.example.com/run.php?test=abc

There are other $_GET variables usable in the link other than test, say id and title, which I don't know about. Is it possible to get the missing variables (If there are any)? In my example case it would be the id and title variables.

3 个答案:

答案 0 :(得分:1)

$_GET是通过网址PHP Docs传递给当前脚本的关联变量数组

所以它将保存所有url参数。你可以这样做:

var_dump($_GET);

然后您可以使用$ _GET参数执行某些操作:

foreach ($_GET as $getParam => $value) {
    echo $getParam . ' = ' . $value . PHP_EOL;
}

答案 1 :(得分:1)

是......

$_GET是一个数组。

所以$_GET[0]可能是测试的价值 $_GET[1]可能是标题的价值

所以你需要知道的是$_GET数组中保存了多少个值或循环遍历数组:

foreach ($_GET as $getParam => $value) {
    echo $getParam . ' = ' . $value . PHP_EOL;
}

另外,如果你做print_r($_GET);,你可以看到数组中所有不同的条目。

答案 2 :(得分:0)

是的,array_keys($_GET)将为您提供密钥,只需迭代它们