在PHP中读取用户环境变量 [英] Reading user environmental variable in php
本文介绍了在PHP中读取用户环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Windows环境变量->用户变量中定义了一个环境变量
I have an environmental variable defined in Windows environmental variables -> user variables
$MY_VARIABLE=mypath
在php中,我试图像下面这样访问它
and in php I tried to access it like below
<?php
echo $_ENV["MY_VARIABLE"];
,但不打印任何内容.我在这里遗漏了一些东西吗,还是PHP无法访问用户环境变量?
but it doesn't print anything. Am I missing something here or is it that PHP doesn't have access to user environmental variables ?
我将PHP作为Apache模块运行(我最初遗漏的重要信息).
推荐答案
Edit your PHP.INI
更改
variables_order = "GPCS"
收件人
variables_order = "EGPCS"
如果它不尝试使用.htaccess
来实现这一目标
It should work by now if it does not try using .htaccess
to achieve this
将以下内容添加到您的.htaccess
Add the following to your .htaccess
SetEnv foo bar
您可以通过PHP获取它
You can get it via PHP
var_dump(getenv('foo'),$_ENV);
这篇关于在PHP中读取用户环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文