Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting All the Environment Variables

Posted on 2001-06-20
6
Medium Priority
?
229 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
Independent Software Vendors: 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 200 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

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.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

604 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