- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在运行Apache/2.2.11 (Win32) PHP/5.3.0
我在 .htaccess 文件中执行了以下操作:
SetEnv FOO bar
如果我打印出$_ENV
PHP 文件中的变量,我得到一个空数组。为什么我的环境变量没有出现在那里?为什么它首先是空的?
虽然我确实找到了我的变量,但它出现在 $_SERVER
中多变的。由于某种原因,它出现了两次。这是为什么?
[REDIRECT_FOO] => bar
[FOO] => bar
看来我可以使用 getenv('FOO')
来获取它,所以也许我应该用它来代替。但我还是有点好奇到底是什么原因造成的。这是 Windows 问题吗?或者说发生了什么?
最佳答案
事实证明这里有两个问题:
<强>1。 $_ENV
仅在 php.ini 允许的情况下才会填充,默认情况下似乎不会这样做,至少在默认的 WAMP server 中不会。安装。
; 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_order
时返回EGPCS
,$_ENV
不再为空。
<强>2。当您在 .htaccess
中使用 SetEnv
时,它最终会出现在 $_SERVER
中,而不是 $_ENV
,我不得不说,当它被命名为 SetEnv
...
# .htaccess
SetEnv ENV dev
SetEnv BASE /ssl/
# php
var_dump($_SERVER['ENV'], $_SERVER['BASE']);
// string 'dev' (length=3)
// string '/ssl/' (length=5)
<强>3。 getenv
函数将始终有效,并且不受 $_ENV 的 PHP 设置的影响 此外,它似乎对大小写不敏感,这可能很有用。
var_dump(getenv('os'), getenv('env'));
// string 'Windows_NT' (length=10)
// string 'dev' (length=3)
关于php - 为什么我的 $_ENV 是空的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42212729/
Lua 从 setfenv() 切换有什么大不了的至 _ENV ? 在各种“新消息”来源中,这一举措被认为是 Lua 5.1 和 5.2 版本之间最重要的变化之一。 但是,PIL 和其他地方给出的示例
我正在运行Apache/2.2.11 (Win32) PHP/5.3.0我在 .htaccess 文件中执行了以下操作: SetEnv FOO bar 如果我打印出$_ENV PHP 文件中的变量,我
注意:我使用的是 Lua 5.3 版。 这个问题是由 Programming in Lua(第 4 版)的练习 25.1(第 264 页)提出的。该练习内容如下: Exercise 25.1: Ada
我正在运行 Apache/2.2.11 (Win32) PHP/5.3.0,我在 .htaccess 文件中执行了以下操作: SetEnv FOO bar 如果我在 PHP 文件中打印出 $_ENV
在我的项目中,我正在执行 XML 文件中包含的一些 lua 函数。我从 C++ 读取 XML,解析代码字符串,执行它们并获得结果。我发现的所有相关问题要么使用专用的 .lua 文件,要么直接在 Lua
我对超全局数组 $_ENV 和 $_SERVER 的理解是否正确? $_ENV: Contains information about environment variables $_SERVER:
通过 $_ENV 变量在您自己的代码中使用 .env 文件中的参数是否正常?当然是在使用 Symfony 4 的项目上下文中。 我有这样的代码: //WebhookUrlBuilder.php cla
我目前正在学习如何使用 Lua C API,虽然我已经成功在 C/C++ 和 Lua 之间绑定(bind)函数,但我有几个问题: 将多个脚本加载到单个 lua_State 中是个好主意吗?有没有办法关
我正在用 Ruby 编写一个小的 CGI 脚本,用于记录访问者的数据。我想记录所有 CGI 环境变量,如 REMOTE_ADDR、USER_AGENT、HTTP_REFERER 等。在 PHP 中遍历
在我的 PHP 代码中,我试图访问我在/etc/profile 中导出的 linux 系统环境变量。 当我在终端中键入“printenv”时,我可以看到设置了变量(称为 MEMCACHED_1)。 但
大多数情况下,我使用过$_SESSION,但是在阅读有关 Session 的内容时,我得到的术语很少 $_ENV & $_COOKIE。 我不清楚什么时候使用哪个,我对我可以使用它们的情况感到困惑。那
getenv() 和 $_ENV 有什么区别? 使用两者之间有什么权衡吗? 我注意到有时 getenv() 可以满足我的需要,而 $_ENV 却不能(例如 HOME)。 最佳答案 根据the php
在使用 GitHub 操作时,我在 $_ENV('ENV') 中遇到 undefined index 错误,但是当我使用 getenv('ENV') 时,我实际上得到了变量我在找。我该如何解决? 最佳
我想为我的数据库凭证使用 Laravel 环境,我这样做了: 在 bootstrap\start.php 中: $env = $app->detectEnvironment(array( 'local
我正在从 CLI 界面运行 PHP 脚本。 我怎样才能像在 Apache 中一样获取运行用户名 ($_ENV['APACHE_RUN_USER'])?现在我正在使用 exec('whoami'),但不
我正在使用 Laravel 5.3 测试我的系统: 在过去的几周里,我的系统运行良好。自上周末以来,我遇到了如下相同的错误 TWICE:- Notice: Undefined variable: _E
当 print(_ENV) 在 windows 上的 zerobrane studio 中使用时,结果为 nil。我们可以将 _ENV 变量设置为预期用途吗?作为代码示例, a = 15
在 apache 环境中 setenv 相当于什么?例如,使用 apache,我可以设置环境“SOMEENV”并通过 $_ENV['SOMEENV'] 在 php 中访问它 - 但我不知道如何
我在 Joomla 中遇到这个错误: Illegal variable `_files` or `_env` or `_get` or `_post` or `_cookie` or `_server
我是一名优秀的程序员,十分优秀!