如何在 IIS 中添加服务器变量 [英] How to add a server variable in IIS

查看:21
本文介绍了如何在 IIS 中添加服务器变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 variable_name variable_value

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:

  1. Clicking on View Server Variables
  2. Click the Add link and enter the variable name
  3. Go back to rules and click the View Rewrite Maps
  4. Click Add Rewrite Map and enter the default value.
  5. Restarted the server.

Full docs can be found at: http://www.iis.net/learn/extensions/url-rewrite-module/setting-http-request-headers-and-iis-server-variables

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.

example: $_SERVER['MY_VARIABLE']

Thanks.

解决方案

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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆