如何为开发环境模拟https环境/ SSL证书?

如何为开发环境模拟https环境/ SSL证书?

问题描述:

I have a PHP application which runs on production like this :

<?php

    /*
    Do some work here
    */

    /* if https environment, redirect to secure next url */
    if(empty(isset["HTTPS"]) == true )  /* FIRST DEPENDECY */
    {
      header("location : https://mynext_prod_url?parameters"); /*SECOND DEPENDENCY */
    }
    else
    {
       header("location : http://mynext_prod_url?parameters");
    }
?>

This works absolutely fine in production where a SSL certificate is installed. To simulate the same scenarios in development, I can overcome first dependency, but how shall I overcome the second ?

/* Development example with workarounds */

  <?php

        /*
        Do some work here
        */
        $_SERVER['HTTPS'] = "TRUE" ;         /* fake HTTPS  */   

        if(isset($_SERVER["HTTPS"]) == true )  /* FIRST DEPENDECY SOLVED */
        {
          /* BUT THIS URL DOES NOT WORK AS IT ONLY EXISTS ON HTTP */
          header("location : https://mynext_dev_url?parameters"); 
        }
        else
        {
           header("location : http://mynext_dev_url?parameters");
        }
    ?>

How can I install a temporary certificate for development purpose ? Or somehow fake the environment .

You can create your own certificates that you can use in development. The mechanism to create certificates varies, by the platform. Here is an article about how to create one using XAMPP on Windows:

http://jaswanttak.wordpress.com/2010/04/15/configure-ssl-on-xampp-and-windows/