Home  >  Article  >  Backend Development  >  Introduction to PHP function getenv and usage examples_PHP tutorial

Introduction to PHP function getenv and usage examples_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:29:481032browse

getenv(PHP 4, PHP 5)

Copy code The code is as follows:
// getenv — Get the value of an environment variable

Function description:
string getenv ( string $varname )

Copy code The code is as follows:
// Get an environment The value of the variable.
// Using phpinfo() you can see a list of all environment variables.

Parameter description:

Copy code The code is as follows:
$varname variable name.

Function return value:

Copy code The code is as follows:
// Return the value of the environment variable varname, if the environment variable varname is not Returns FALSE if it exists.

Function application example:

Copy code The code is as follows:
// getenv() usage example
$ip = getenv('REMOTE_ADDR');

// Or simply just use global variables ($_SERVER or $_ENV)
$ip = $_SERVER['REMOTE_ADDR'];
?>

You can see the configuration information of the entire PHP environment through phpinfo, so what should you do if you want to get one of the variable information?
The following is a practical demonstration. For example, I want to obtain the following information:

Introduction to PHP function getenv and usage examples_PHP tutorial

Then, the source code of PHP is:

Copy code The code is as follows:
echo getenv('userprofile');// C :Windowssystem32configsystemprofile

Very easy, right? Hey~

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/769245.htmlTechArticlegetenv(PHP 4, PHP 5) Copy the code as follows: // getenv — Get the value function of an environment variable Description: string getenv ( string $varname ) Copy the code as follows: // Get a...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn