Benchmarks Online

Skip Navigation Links

Page One

Campus Computing News

Spring Break Hours

Eaglenet Wireless Network Update

Jaws 6.0 has arrived!

Today's Cartoon

RSS Matters

The Network Connection

Link of the Month


Short Courses

IRC News

Staff Activities

Subscribe to Benchmarks Online


Accessing Variables in Safe Mode PHP

By J.P. Williams, Central Web Support

As of February 1st we turned off register globals for When register globals is turned off the PHP module of the apache server does not automatically make variables globally accessible to the script that you are either posting to, or using the get method and passing variables on the command-line ie: ( The variables and values are stored in the server variable $_GET or $_POST depending on which method you are using. What that means for those of you that use PHP on Web2 is that when using POST or GET methods on forms using PHP as the scripting language you will have to extract the variables and values from the corresponding server variable. To extract the values for the variables first and last in the above example you will have to access them as $_GET['first'] and $_GET['last']; or if they are posted from a form to the script myscript.php the variable would be $_POST['first'] and $_POST['last']. The following code snippet will fix the problem so that you will be able to access the variables with just $first and $last.

$ArrayList = array("_GET", "_POST", "_COOKIE", "_SERVER");

foreach($ArrayList as $gblArray){

 $keys = array_keys($$gblArray);

 foreach($keys as $key){

 $$key = trim(${$gblArray}[$key]);




What this little piece of code does is cycle through the server variables and extract the variable names and values. You can either insert this piece of code at the top of your script or create a php file that contains just this code and do an include in your script at the top before you try to access the value of the variables that you passed in. To include a file in PHP you would use the following syntax assuming that you have a file named globalinc.php that has the above code in it:

Include code for accessing passed variables

Start accessing or processing passed variables
print “Hello “ . $first;
print “, how is the “ . $last . “ family?”;


Return to top