简体   繁体   English

在本地 wamp-server 上欺骗 $_SERVER['HTTPS'] 以进行测试

[英]Spoof $_SERVER['HTTPS'] on local wamp-server for testing

Is it possible to configure my local setup (running Wampserver) so that my PHP application thinks HTTPS is enabled locally?是否可以配置我的本地设置(运行 Wampserver),以便我的 PHP 应用程序认为 HTTPS 在本地启用? The application requires HTTPS (by checking $_SERVER['HTTPS'] ) before doing stuff, but I don't want to go through the hassle of a full HTTPS setup locally.该应用程序在执行操作之前需要 HTTPS(通过检查$_SERVER['HTTPS'] ),但我不想 go 在本地完成完整的 Z0E8433F9A404F1F3BA601C14B2 设置的麻烦。 Thanks.谢谢。

Edit: I should mention this isn't an application I wrote, just one I am tasked with maintaining.编辑:我应该提到这不是我编写的应用程序,只是我负责维护的应用程序。 This check is performed in many places (50-100) around the server.此检查在服务器周围的许多地方 (50-100) 执行。

Shouldn't be too hard.应该不会太难。 Even though it is a superglobal, you can still redefine it like any other variable.即使它是一个超全局变量,您仍然可以像任何其他变量一样重新定义它。 Do this at the top of your code, and when it gets to the check, it should still recognize it as true.在代码的顶部执行此操作,当它进行检查时,它仍应将其识别为 true。

$_SERVER['HTTPS'] = true;

You can mock up this variable in your init file by adding:您可以通过添加以下内容在您的 init 文件中模拟此变量:

$_SERVER['HTTPS'] = true;

Move the check into an object将支票移动到 object

   class Request
   {
       function isHttps()
       {
            // check for local site here,
            // or better still, use a DevRequest class or a Mock to pass
            // your local requirements
       }

   }

and then use然后使用

if($request->isHttps()) {...} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM