• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

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.
0
theravada_maha
Asked:
theravada_maha
  • 3
  • 2
1 Solution
 
jimmy282Commented:
$headers = getallheaders();
while (list ($header, $value) = each ($headers)) {
    echo "$header: $value<br>\n";
}
     
Jimmy
0
 
meetygCommented:
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>");
}

?>
////////////////////////////////////////////////////
0
 
theravada_mahaAuthor Commented:
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
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
meetygCommented:
Those variables are not environment variables!!!
Those are either POST or  GET variables, depending on what METHOD you form uses.

If your form send the variables using the GET method, you can get them like this:
------------------------------------------------
<?
foreach($HTTP_GET_VARS as $VarName => $VarValue)
{
    echo("<b>".$VarName."</b> = ".$VarValue."<BR>");
}
?>
------------------------------------------------

But if your form uses the POST method, you can get them like this:
------------------------------------------------
<?
foreach($HTTP_POST_VARS as $VarName => $VarValue)
{
    echo("<b>".$VarName."</b> = ".$VarValue."<BR>");
}
?>
------------------------------------------------

Notice that the only difference is that I am getting the information either from the $HTTP_GET_VARS array, or the $HTTP_POST_VARS array.
These arrays are automatically created when form variables are sent to it.




0
 
theravada_mahaAuthor Commented:
Great it works now, thanks!

Ther.
0
 
theravada_mahaAuthor Commented:
Great it works now, thanks!

Ther.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now