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.


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


How can I access environment variables from php?


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).

   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";

Generated 12:02:10 on Oct 21, 2020