Solved

Getting All the Environment Variables

Posted on 2001-06-20
6
221 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 dynamically set the form action using jQuery.

862 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

23 Experts available now in Live!

Get 1:1 Help Now