Getenv() PHP Function

Using Getenv() to Retrieve an IP Address or Document Root

The getenv() function is used to retrieve the value of an environment variable in PHP. The getenv() function returns the value of a specified environment variable. The function follows the syntax getenv (varname). 

What Are Environment Variables

Environment variables are imported into the environment where the PHP code runs. You probably have more than one deployment of code: a local one for development and one in the cloud, each with different credentials.

The environment variables for any two locations are different, so it makes sense not to include them in the main code.

Examples of the Getenv() Function

Below are some examples of environment variables you can use. These code examples retrieve an IP address, the admin's contact information and the document root.

 
 
 
Format
mla apa chicago
Your Citation
Bradley, Angela. "Getenv() PHP Function." ThoughtCo, Aug. 21, 2017, thoughtco.com/getenv-php-function-2694057. Bradley, Angela. (2017, August 21). Getenv() PHP Function. Retrieved from https://www.thoughtco.com/getenv-php-function-2694057 Bradley, Angela. "Getenv() PHP Function." ThoughtCo. https://www.thoughtco.com/getenv-php-function-2694057 (accessed January 22, 2018).