DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Kunal has posted 6 posts at DZone. View Full User Profile

PHP GET And POST Variables

  • submit to reddit
        // The following code will easily retrieve all of the GET and POST data for you and load it into appropriately named PHP variables. The same code will also work to get parameters added to the end of URLs via other methods other than using GET with a form.

$q = explode("&",$_SERVER["QUERY_STRING"]);
foreach ($q as $qi)
  if ($qi != "")
    $qa = explode("=",$qi);
    list ($key, $val) = $qa;
    if ($val)
      $$key = urldecode($val);
reset ($_POST);
while (list ($key, $val) = each ($_POST))
  if ($val)
    $$key = $val;


Snippets Manager replied on Wed, 2006/08/02 - 10:38am

Cripes, why wouldn't you use a better method? Say, extract($_GET), or import_request_variables('G', 'get_')?