faqts : Computers : Programming : Languages : PHP : kms : General

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

37 of 42 people (88%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

Can I access Environment Variables from inside PHP scripts?
What Environment Variables are available to my PHP script?
What HTTP_ variables are available in PHP?

Jul 8th, 2002 22:10
Philip Olson, Nathan Wallace,


The PHP manual lists many of these predefined variables here:
  http://www.php.net/manual/en/language.variables.predefined.php
There are a few ways to access these predefined variables.  Here are
some examples using HTTP_REFERER:
  <?php
    // works as of PHP 3
    print $HTTP_SERVER_VARS['HTTP_REFERER'];
    // works as of PHP 4.1.0
    print $_SERVER['HTTP_REFERER'];
    // works if the php directive register_globals = on.
    // as of PHP 4.2.0 this directive defaults to off.
    print $HTTP_REFERER;
  ?>
For a complete list of environment variables available to your scripts, 
use phpinfo{} to see "what's available", you should do this as server 
setups allow for different environment variables.  Use phpinfo as such:
  <?php phpinfo() ?>
Another way to access these variables is by use getenv():
  http://www.php.net/manual/en/function.getenv.php
On a related note, you can read about register_globals here:
  http://www.php.net/manual/en/configuration.php#ini.register-globals