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?

148 of 158 people (94%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

Now with PHP4, I can't no more pass variables in a URL http://ddd.ddd/ddd.php?toto=value ******* toto is always undefined ??

May 20th, 2002 09:24
Philip Olson, Jens Clasen, Yves MAHE,


If you have the following URL:
  http://www.example.com/foo.php?fruit=apple
The variable $fruit will automatically exist if the PHP directive
register_globals = on.  As of PHP 4.2.0, the default for this 
directive is off and since PHP 4.1.0 it's been encouraged to not 
rely on the behavior.  There are many other methods:
  print $HTTP_GET_VARS['fruit']; // apple
  print $_GET['fruit'];          // apple
  import_request_variables('g', 'g_');
  print $g_fruit;                // apple
  extract($HTTP_GET_VARS);
  print $fruit;                  // apple
$HTTP_GET_VARS has been around forever, $_GET is a superglobal and 
it along with import_request_variables() became available in PHP 4.1.0,
and extract() is another possability.
Some related manual entries are:
  http://www.php.net/manual/en/language.variables.predefined.php
  http://www.php.net/manual/en/language.variables.external.php
  http://www.php.net/release_4_1_0.php
This topic has been discussed in the PHP mailing lists a few times  
too, here are a few threads:
  http://aspn.activestate.com/ASPN/Mail/Message/php-general/1104973
  http://aspn.activestate.com/ASPN/Mail/Message/php-general/1188233