dongshang5862
dongshang5862
2011-10-19 05:29

如何为开发环境模拟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 .

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dsdt66064367 dsdt66064367 10年前

    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/

    点赞 评论 复制链接分享