Programming C# C++ (7) Delphi (618) Java (8) JavaScript (29) perl (9) php (4) GTK (2) VBScript (1) Visual Basic (1)
Exchange Links About this site Links to us 
|
Accessing environment variables from php
1 comments. Current rating: (1 votes). Leave comments and/ or rate it.
Question: How can I access environment variables from php?
Answer: There are two possiblities:
- You can use the function getenv() which will work from the CLI as well as via http
- If you're using php via http, then you can use the global array HTTP_ENV_VARS where all environment variables are exported. You need to declare this as a global identifier (see second part of code example).
 | |  | | <?php
function show_home_directory() {
echo getenv("HOME"). "<br>\n";
global $HTTP_ENV_VARS;
echo $HTTP_ENV_VARS["HOME"] . "<br>\n";
}
show_home_directory();
?>
| |  | |  |
Comments:
|
anonymous from United States
|
 |
|
|
|
|