开发者

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? The application requires HTTPS (by checking $_SERVER['HTTPS']) before doing stuff, but I don't want to go through the hassle of开发者_如何学C a full HTTPS setup locally. 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.


You can mock up this variable in your init file by adding:

$_SERVER['HTTPS'] = true;


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.

$_SERVER['HTTPS'] = true;


Move the check into an 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()) {...} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜