Link to home
Start Free TrialLog in
Avatar of theravada_maha
theravada_maha

asked on

Getting All the Environment Variables

How can I get all the environment variables? I'm looking for an array with keys of environment variables.

I need to access a variable without knowing its name.

Ther.
Avatar of jimmy282
jimmy282
Flag of United Kingdom of Great Britain and Northern Ireland image

$headers = getallheaders();
while (list ($header, $value) = each ($headers)) {
    echo "$header: $value<br>\n";
}
     
Jimmy
Avatar of meetyg
meetyg

If you are using PHP4 and up, you can use:
$HTTP_ENV_VARS

this variable is an array that holds all the environment variables.

This loop will echo each Environment variable and its value:
/////////////////////////////////////////////////////
<?
 foreach($HTTP_ENV_VARS as $VarName => $VarValue)
{
     echo("<b>".$VarName."</b> = ".$VarValue."<BR>");
}

?>
////////////////////////////////////////////////////
Avatar of theravada_maha

ASKER

Actually I'm looking for a way to grab the environment variables of a form, for example. Let's say I have a form that sends 45 variables to the action.php or whatever, I can't just manually recall all those variables because they're generated by php itself, how can I get those?

Eric
ASKER CERTIFIED SOLUTION
Avatar of meetyg
meetyg

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great it works now, thanks!

Ther.
Great it works now, thanks!

Ther.