DelphiFAQ Home Search:
General :: Programming :: php
Find help with php (PHP: Hypertext Preprocessor), an open source, server-side, HTML embedded scripting language used to create dynamic Web pages.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Accessing environment variables from php

Question:

How can I access environment variables from php?

Answer:

There are two possiblities:
  1. You can use the function getenv() which will work from the CLI as well as via http
  2. 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() {
     # works from CLI and in web browser:
     echo getenv("HOME"). "<br>\n";
 
     # only via http
     global $HTTP_ENV_VARS;
     echo $HTTP_ENV_VARS["HOME"] . "<br>\n";
   }
 
   show_home_directory();
  ?>
 

Generated 12:02:57 on Nov 20, 2018