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'];


2 Answers 2


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

  • thanks just changed above. Is there any reason the $_GET shouldn't work above? This is inside my module page function.
    – frosty
    Commented Aug 11, 2011 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']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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