faqts : Computers : Programming : Languages : PHP : Common Problems : Variables

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

41 of 50 people (82%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

Why do I get the error: undefined variable: QUERY_STRING for predefined variable $QUERY_STRING ?

Feb 1st, 2002 21:33
Philip Olson, Gerald Clerc, Onno Benschop,


"undefined variable" is a PHP error of level E_NOTICE.  QUERY_STRING is
a Predefined Variable that's available in PHP.
If the register_globals PHP directive (in php.ini) is off, the variable
$QUERY_STRING will not exist (undefined).  If register_globals is on,
$QUERY_STRING will exist*.  For this reason, it is preferred to NOT 
use $QUERY_STRING.  More reliable ways on calling QUERY_STRING are:
  getenv('QUERY_STRING')           // see: http://www.php.net/getenv
  $_SERVER['QUERY_STRING']         // $_SERVER available as of PHP 4.1.0
  $HTTP_SERVER_VARS['QUERY_STRING']
For information purposes, QUERY_STRING is generated by the web server
(such as Apache) and is defined as:
QUERY_STRING
  The information which follows the ? in the URL  which referenced 
  this script. This is the query information. It should not be 
  decoded in any fashion. This variable should always be set when 
  there is query information, regardless of command line decoding.
  http://hoohoo.ncsa.uiuc.edu/cgi/env.html 
* Before php version 4.2.0, it was common to have register_globals on
which made all predefined variables register, like, $QUERY_STRING.  See 
also directive variables_order and:
  http://www.php.net/manual/en/language.variables.predefined.php