Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 610
MarcoS Avatar asked May 25 '11 15:05

MarcoS


Video Answer


2 Answers

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].

like image 182
Dan Avatar answered Sep 27 '22 22:09

Dan


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.

like image 35
Brady Avatar answered Sep 27 '22 22:09

Brady