修复IIS和PHP变量–自行设置$ _SERVER ['REQUEST_URI']

About 8 months into my programming career I needed to code a content management system (CMS). This was quite a challenge so early into my professional journey but I was up to it. The front-end was the easiest part of the project -- a lot quick SQL queries for bringing intros and conclusions to pages that needed to be static due to PHP programming, a sub-navigation builder (the menu was stored in the DB), and the usual take-forever forms.

在进入编程生涯大约8个月后,我需要编写内容管理系统(CMS)的代码。 在我职业生涯的早期,这是一个很大的挑战,但我可以应付。 前端是该项目中最简单的部分-很多SQL查询,用于将介绍和结论带入由于PHP编程,子导航构建器(菜单存储在DB中)而需要静态的页面中,和通常的永久性形式。

The most time-consuming part of the project was creating an administrative panel. The administrative panel needed to be highly flexible and portable so that it could be used on other projects. In the end, the framework for the administrative panel has been perfect for all projects since that one. We keep adding modules which save time and allow time for more front-end programming.

该项目最耗时的部分是创建一个管理面板。 管理小组必须高度灵活且可移植,以便可以在其他项目中使用。 最后,自该项目以来,行政小组的框架对于所有项目都是完美的。 我们不断添加模块,以节省时间并留出时间进行更多前端编程。

With that particular project, however, we ran into a problem that we didn't foresee. -- the customer informed us that we needed to host the website on an IIS server. This was not great news but we knew that IIS would support PHP so we didn't panic. The big problem I ran into is that IIS does not support PHP's $_SERVER['REQUEST_URI'] variable and worse is that I didn't know this until it was time to launch.

但是,对于该特定项目,我们遇到了一个我们无法预见的问题。 -客户通知我们,我们需要将网站托管在IIS服务器上。 这不是一个好消息,但是我们知道IIS将支持PHP,因此我们不必惊慌。 我遇到的最大问题是IIS不支持PHP的$ _SERVER ['REQUEST_URI']变量,更糟糕的是,直到启动时我才知道这一点。

I used the $_SERVER['REQUEST_URI'] all over the administration panel. Every "page" of the website ran through the index.php to give me MVC funtionality. Doing so made me need to use the self-referencing $_SERVER['REQUEST_URI'] variable because it provided me the all-important querystring variables I needed to keep my place in the file.

我在整个管理面板上都使用了$ _SERVER ['REQUEST_URI'] 。 网站的每个“页面”都通过index.php运行,从而为我提供了MVC功能。 这样做使我需要使用自引用$ _SERVER ['REQUEST_URI']变量,因为它为我提供了在文件中保留自己位置所需的所有重要查询字符串变量。

How'd I fix the problem? It was actually quite simple:

我该如何解决这个问题? 实际上很简单:

if (!isset($_SERVER['REQUEST_URI']))
{
       $_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'],1 );
       if (isset($_SERVER['QUERY_STRING'])) { $_SERVER['REQUEST_URI'].='?'.$_SERVER['QUERY_STRING']; }
}

This probably seems easy and obvious to most but at the time I was quite new. Hopefully this can help someone save a lot of time!

对于大多数人来说,这似乎很容易并且显而易见,但是当时我还很陌生。 希望这可以帮助某人节省很多时间!

翻译自: https://davidwalsh.name/iis-php-server-request_uri

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值