Solved

Getting All the Environment Variables

Posted on 2001-06-20
6
226 Views
Last Modified: 2006-11-17
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
Comment
Question by:theravada_maha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:jimmy282
ID: 6213099
$headers = getallheaders();
while (list ($header, $value) = each ($headers)) {
    echo "$header: $value<br>\n";
}
     
Jimmy
0
 

Expert Comment

by:meetyg
ID: 6214795
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
 

Author Comment

by:theravada_maha
ID: 6235570
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Accepted Solution

by:
meetyg earned 50 total points
ID: 6235748
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
 

Author Comment

by:theravada_maha
ID: 6235990
Great it works now, thanks!

Ther.
0
 

Author Comment

by:theravada_maha
ID: 6235993
Great it works now, thanks!

Ther.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question