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, Jan. 29, 2020, thoughtco.com/getenv-php-function-2694057. Bradley, Angela. (2020, January 29). 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 March 29, 2024).