Reputation: 13564
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
Upvotes: 6
Views: 10744
Reputation: 236
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.
Upvotes: 5
Reputation: 4873
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);
Upvotes: 3
Reputation: 537
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]
.
Upvotes: 7