Solved

Getting All the Environment Variables

Posted on 2001-06-20
6
220 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
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

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

Expert Comment

by:meetyg
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Accepted Solution

by:
meetyg earned 50 total points
Comment Utility
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
Comment Utility
Great it works now, thanks!

Ther.
0
 

Author Comment

by:theravada_maha
Comment Utility
Great it works now, thanks!

Ther.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now