How to read a parameter from an HTTP request string

I have the following URL

http://www.example.com/node/add/forum/3?gids[]=13 

I want to get the value 13 from my module.

I tried with

 $_GET['gid[]'] 

and

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

but i always get null .

How can i do this? Thanks

+6
source share
3 answers

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

+7
source

Because it is tagged with the word "drupal" and appears in a Google search. Drupal 7 does this and simplifies the use of drupal_get_query_parameters () . This will return the associated array of all variables and values ​​from the query string immediately.

Using this, when you store information coming from a URL, it was sanitized for XSS and SQLi attacks.

+4
source

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

 $gids = filter_input(INPUT_GET, 'gids', FILTER_DEFAULT, FILTER_FORCE_ARRAY | FILTER_FORCE_ARRAY); 
+3
source

Source: https://habr.com/ru/post/889011/


All Articles