adding a new key,value pair to the $_SERVER global array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mechamecha
Forum Commoner
Posts: 32
Joined: Thu May 31, 2007 8:49 pm

adding a new key,value pair to the $_SERVER global array

Post by mechamecha »

Hello,
Is it possible to add a new key-value pair to the $_SERVER superglobal array?

For example, when portions of facebook's code was leaked, there were many include clauses containing $_SERVER['PHP_ROOT']. I am guessing that $_SERVER['PHP_ROOT'] is storing the path to where all of the source code is kept, a path which is not accessible to an outsider.

I want to do the same, but I haven't found any resources that explain how this is done. Is modifying the $_SERVER array done by changing the configuration on the server app, such as appache?

Or perhaps there is a better approach to storing the path to a directory outside of the public one?

THanks
jeffery
Forum Contributor
Posts: 105
Joined: Mon Apr 03, 2006 3:13 am
Location: Melbourne, Australia
Contact:

Post by jeffery »

If you have Apache module mod_env (environment) turned on, in an .htaccess file you can do this:

Code: Select all

SetEnv PHP_ROOT "/usr/share/application/"
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The following works.

Code: Select all

$_SERVER['floob'] = 'party time';
Post Reply