如何在IIS中添加服务器变量 [英] How to add a server variable in IIS
问题描述
我对IIS7不太熟悉,我需要创建一个服务器变量,以便可以在我的PHP代码中访问它.我可以使用以下命令在Apache中轻松完成此操作:
I am not very familiar with IIS7 and I need to create a server variable so that I can access it within my PHP code. I can easily accomplish this in Apache by using:
SETENV变量名变量值
SETENV variable_name variable_value
.但是,在IIS中完成此操作似乎有点秘密.我在网上寻找信息,并通过以下步骤使用URL重写模块可以找到状态的最接近的东西:
in the .htaccess file. However accomplishing this in IIS seems to be a bit of a secret. I have looked online for info and the closest thing I can find states using the URL Rewrite Module using these steps:
- 单击View Server变量
- 单击添加"链接并输入变量名称
- 返回规则,然后单击查看重写地图"
- 单击添加重写映射",然后输入默认值.
- 重新启动服务器.
Full docs can be found at: http://www.iis.net/learn/extensions/url-rewrite-module/setting-http-request-headers-and-iis-server-variables
我遵循了该规定,但仍然无法正常工作.任何想法如何做到这一点?甚至有可能在IIS中执行此操作?我要做的就是设置一个带有静态值的服务器变量.
I followed that but it still doesn’t work. Any ideas how this is done? Is it even possible to do this in IIS? All I want to do is set up a server variable with a static value.
示例:$ _SERVER ['MY_VARIABLE']
example: $_SERVER['MY_VARIABLE']
谢谢.
推荐答案
我通过使用PHP auto_prepend_file指令解决了此问题.可以在这里找到更多信息: http://www.php.net/manual/zh-CN/ini.core.php#ini.auto-prepend-file
I solved this by using the PHP auto_prepend_file directive. More information can be found here: http://www.php.net/manual/en/ini.core.php#ini.auto-prepend-file
只需创建一个文件,即可将所需的值添加到$ SERVER数组中,并将其设置为auto_prepend_file即可.这将适用于任何服务器,而不仅限于IIS.
Just create a file that adds the desired value to the $SERVER array, set that as the auto_prepend_file and you are good to go. This will work with any server, not just IIS.
这篇关于如何在IIS中添加服务器变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!