Home  >  Article  >  Backend Development  >  PHP函数getenv使用实例介绍_PHP教程

PHP函数getenv使用实例介绍_PHP教程

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

分享下PHP函数getenv使用实例,getenv函数主要用来获取一个环境变量的值,常见的PHP探针程序都是使用的getenv函数。

getenv(PHP 4, PHP 5)
// getenv — 获取一个环境变量的值
函数说明:www.jbxue.com
string getenv ( string $varname )

// 获取一个环境变量的值。
// 使用 phpinfo() 你可以看到所有环境变量的列表。
参数说明:
$varname 变量名。
函数返回值:
// 返回环境变量 varname 的值, 如果环境变量 varname 不存在则返回 FALSE。
函数应用实例:

php
// getenv() 使用示例
$ip = getenv('REMOTE_ADDR');
// 或简单仅使用全局变量($_SERVER 或 $_ENV)
$ip = $_SERVER['REMOTE_ADDR'];
?>

通过phpinfo可以看到整个PHP环境的配置信息,那么想要获取其中一个变量信息要咋办呢?

获取如下信息:

php代码:

echo getenv('userprofile');// C:\Windows\system32\config\systemprofile

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/768445.htmlTechArticle分享下PHP函数getenv使用实例,getenv函数主要用来获取一个环境变量的值,常见的PHP探针程序都是使用的getenv函数。 getenv(PHP 4, PHP 5) // getenv 获取...
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