3

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 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.

TJ L
  • 23,914
  • 7
  • 59
  • 77

3 Answers3

2

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;
Sam Becker
  • 19,231
  • 14
  • 60
  • 80
2

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

$_SERVER['HTTPS'] = true;
hsz
  • 148,279
  • 62
  • 259
  • 315
  • I did find a file included nearly everywhere before this check, so I was able to include this statement there. Thanks. – TJ L Jun 02 '11 at 14:44
0

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()) {...} 
Ken
  • 77,016
  • 30
  • 84
  • 101
  • This is how I would do it if I designed the system. The system is kind of a mess and the check is performed sporadically throughout it. – TJ L Jun 08 '11 at 18:41