English 中文(简体)
我的美元“ENV”为什么空出?
原标题:Why is my $_ENV empty?
  • 时间:2010-09-23 17:15:22
  •  标签:
  • php
  • apache

I m entre Apache/2.2.11 (Win32) PHP/5.3.0,我在“htaccess”的档案中做了以下工作:

SetEnv FOO bar

如果我在PHP文档中打印$_ENV变量,我就有一个空阵。 为什么我的环境变数出现在那里? 为什么它首先空洞?

我确实发现我的变数,但出现在<代码>_SERVER变量上。 出于某种原因,它似乎有两倍。 为什么如此?

[REDIRECT_FOO] => bar
[FOO] => bar

看来我可以使用<代码>getenv(FOO ),因此,我或许应该只使用这个编号。 但是,我仍然对造成这种情况的原因感到奇怪。 这个问题是否是一个Windows? 还是正在做些什么?

最佳回答

这里有两个问题:

; This directive determines which super global arrays are registered when PHP
; starts up. If the register_globals directive is enabled, it also determines
; what order variables are populated into the global space. G,P,C,E & S are
; abbreviations for the following respective super globals: GET, POST, COOKIE,
; ENV and SERVER. There is a performance penalty paid for the registration of
; these arrays and because ENV is not as commonly used as the others, ENV is
; is not recommended on productions servers. You can still get access to
; the environment variables through getenv() should you need to.
; Default Value: "EGPCS"
; Development Value: "GPCS"
; Production Value: "GPCS";
; http://php.net/variables-order
variables_order = "GPCS"

当我确定variables_orderEGPCS,$_ENV已不复存在。

<2. 当您在上使用时,在_SERVER时,而不是在_ENV上填写,而I gotta说,在名称时,这是一种令人沮丧的混淆。 SetEnv

# .htaccess
SetEnv ENV dev
SetEnv BASE /ssl/

# php
var_dump($_SERVER[ ENV ], $_SERVER[ BASE ]);

// string  dev  (length=3)
// string  /ssl/  (length=5)

<代码>getenv功能将始终有效,不受PHP设定值_ENV的影响。 此外,似乎对这种情况不敏感,这可能是有益的。

var_dump(getenv( os ), getenv( env ));

// string  Windows_NT  (length=10)
// string  dev  (length=3)
问题回答

。 在我的服务器上,他们似乎也如此。 它可以在快车下运行。 而且,如果加上代谢,最有可能清理整个环境。 可能需要额外配置,以便重新编号PassEnv。 至于为什么要为你工作,我没有cl。 但是,所有现象都与你的服务器和网站组合有关。 在服务器上,他们应当知道。





相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签