Home  >  Article  >  Backend Development  >  php cli 下怎么给$_SERVER 增加变量

php cli 下怎么给$_SERVER 增加变量

WBOY
WBOYOriginal
2016-06-06 20:32:021058browse

非cli 而且用nginx 的时候
可以用 fastcgi_param 给 $_SERVER 增加属性;

但在cli 模式下怎么做呢

回复内容:

非cli 而且用nginx 的时候
可以用 fastcgi_param 给 $_SERVER 增加属性;

但在cli 模式下怎么做呢

$_SERVER是个变量,变量就意味着你可以轻松修改它……

<code>php</code><code>$_SERVER['ooxx'] = '囧'; //想了想还是给个例子吧
</code>

环境变量会出现在$_SERVER中,所以直接修改环境变量就行

<code>$ YOUR_VARIABLE=here php -r 'print_r($_SERVER);'|grep here
    [YOUR_VARIABLE] => here
$ export ANOTHER_VAR=this
$ php -r 'print_r($_SERVER);'|grep this
    [ANOTHER_VAR] => this
</code>
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