Science, Tech, Math › Computer Science Getenv() PHP Function Using Getenv() to Retrieve an IP Address or Document Root Share Flipboard Email Print Computer Science PHP Programming Tutorials MySQL Commands Perl Python Java Programming Javascript Programming Delphi Programming C & C++ Programming Ruby Programming Visual Basic View More By Angela Bradley Angela Bradley Computer Science Expert B.A, History, Eastern Oregon University Angela Bradley is a web designer and programming expert with over 15 years of experience. An expert in iOS software design and development, she specializes in building technical hybrid platforms. Learn about our Editorial Process Updated on January 28, 2019 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. Cite this Article 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 30, 2023). copy citation Featured Video