函数原型:
parse_str ( string $encoded_string [, array &$result ] ) : void
将$encoded_string解析为一个关联数组,如果没有返回结果的话,则把数组的value赋值给$key,即$key=value,如果有返回结果,那么将结果返回到$result中,仍为关联数组(如果变量就是数组那此时编程二维数组)
//Example
<?php
$str="first=1&second=2&third=3"
parse_str($str);
/*此时相当于
$first=1;
$seconde=2;
$third=3;
*/
parse_str($str,$output);
/*此时相当于
$output['first']=1;
$output['second']=2;
$output['third'][0]=3;
*/
-
需要注意的是,这个函数存在变量覆盖漏洞。
由于它会解析$encoded_string为关联数组并赋值,如果前面已经出现过与key同名的全局变量,那么此处的解析就会造成变量值的覆盖。
由此,如果解析的url是由我们传入的,那么我们可以通过修改key的值value值来覆盖原有的全局变量$key的值
由于其不安全性,在php7.2中已经变成"highly DISCOURAGED and DEPRECATED"