I've trying to get the querystring from within a module.

I've tried the following. However the following always returns A


$l = "A";
if ( !empty($_SERVER['l']) ) {
    $l = $_SERVER['l'];

/* edit */

    $l = "A";
if ( !empty($_GET ['l']) ) {
  $l = $_GET ['l'];


The query string is stored in $_SERVER['QUERY_STRING'], the same way as when not using Drupal. You can access the individual variables of the query string using the $_GET array, the same way as when not using Drupal (with one exception: $_GET['q'] is the canonical Drupal path, not the one assigned using the Path module).

| improve this answer | |
  • thanks just changed above. Is there any reason the $_GET shouldn't work above? This is inside my module page function. – frosty Aug 11 '11 at 19:31

Oswald is correct. Alternatively, in Drupal 7, you can use drupal_get_query_parameters():

$query_parameters = drupal_get_query_parameters();
if (!empty($query_parameters['l'])) {
  $l = $query_parameters['l']
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.