faqts : Computers : Programming : Languages : PHP : Common Problems : Forms and User Input

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

179 of 212 people (84%) answered Yes
Recently 2 of 10 people (20%) answered Yes

Entry

Undefined variable PHP_SELF and other submited form variables

Dec 1st, 2002 09:54
Philip Olson, Isaac L, Hartono Liduwan,


Please read the following manual page:
  http://www.php.net/variables.predefined
As of PHP 4.2.0 the default for the PHP directive register_globals
went from on to off.  This is a MAJOR change in PHP.  It also 
affects SERVER variables such as PHP_SELF.
So, in regards to PHP_SELF, $PHP_SELF will ONLY exist if
register_globals is on.  Regardless of the setting you can always
use either:
  $_SERVER['PHP_SELF']
  $HTTP_SERVER_VARS['PHP_SELF']
Superglobals such as $_SERVER became available as of PHP 4.1.0.  The 
older $HTTP_SERVER_VARS has been available since PHP 3.  Anyway, again 
please read more about predefined variables here:
  http://www.php.net/variables.predefined
Note that this applies to ALL variables, whether they be GET, POST, 
SERVER, SESSION, COOKIE, FILE... So PLEASE read about this change in 
the manual (links provided in this faqt).  Knowing what 
register_globals does is IMPORTANT!
On a related note, using GET as an example.  The following behavior 
would be like posting a GET form.  $_POST for a POST form.  $_REQUEST 
for either including COOKIE.  Anyway, read the manual for more details:
  http://www.example.com/foo.php?apple=red&banana=yellow
  print $_GET['apple'];          // If php version 4.1.0 or greater
                                 // This is prefered
  print $HTTP_GET_VARS['apple']; // Will always work
  print $apple;                  // ONLY if register_globals = on
Read me!
  http://www.php.net/variables.external
See also: extract() and import_request_variables().