开发者

How to read parameter from the HTTP query string

I have the following URL

http://www.example.com/node/add/forum/3开发者_开发百科?gids[]=13

I want to get the value 13 from within my module.

I've tried with

$_GET['gid[]']

and with

$_GET['gids%5B%5D']

but I always get null.

How can I do this? Thanks


Assuming the URL is correctly encoded (gids%5B%5D) and that's the only element in the array, then the contents of that first element in gids would be in $_GET['gids'][0].


Since this is tagged with the keyword "drupal" and comes up on Google searches. The Drupal 7 way of doing it and makes it easy is to use drupal_get_query_parameters(). This will return an associate array of all variables and values from the query string all at once.

By using this, when you store the information coming from the URL it has been sanitized for XSS and SQLi attacks.


In PHP 5.2+, use filter_input() to read GET and POST variables:

$gids = filter_input(INPUT_GET, 'gids', FILTER_DEFAULT, FILTER_FORCE_ARRAY | FILTER_FORCE_ARRAY);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜