DelphiFAQ Home Search:

Accessing environment variables from php

 

comments5 comments. Current rating: 3 stars (3 votes). Leave comments and/ or rate it.

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();
 ?>

Comments:

2006-08-02, 14:59:58
anonymous from United States  
rating
2009-04-16, 00:26:37
anonymous from Pakistan  
rating
thanks.
2009-07-04, 13:13:57
anonymous from United States  
rating
<br>
<br>

was the view-source result
2009-08-09, 01:35:46
anonymous from Islamabad, Pakistan  
Know i will access envirnment variable in an easy way
lot of thanks ,God may leave u at right way. Ameen!
2009-12-10, 00:22:01
anonymous from Pakistan  
http://www.delphifa.."""""""""" target=_blank > http://www.delphifa.."""""""""" target=_blank > http:// http://www.d.."""""""""" target=_blank > http://www.delphifa.."""""""""" target=_blank > http://www http://ww.."""""""""" target=_blank > http://www.delphifa.."""""""""" target=_blank > http://www http://ww.."""""""""" target=_blank > http://www.delphifa.."""""""""" target=_blank > http://www.delphifa.."""""""""" target=_blank > http://ww http://www.."""""""""" target=_blank > http://www.delphifa.."""""""""" target=_blank > http://www.delphifa..f""""""""" target=_blank > http:// http://www.d..if"""""""" target=_blank > http://www.delphifa..gif""""""" target=_blank > http://www.delphifa...gif"""""" target=_blank > http://www.delphifa..2.gif""""" target=_blank > http://www.delphifa..22.gif"""" target=_blank > http://www.delphifa..c22.gif""" target=_blank > http://www.delphifa../c22.gif"" target=_blank > http://www.delphifa..s/c22.gif" target=_blank > http://www.delphifa..es/c22.gif

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: