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

发布于 2024-12-10 16:44:24 字数 1050 浏览 0 评论 0原文

我有一个在生产环境中运行的 PHP 应用程序,如下所示:

<?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");
    }
?>

这在安装了 SSL 证书的生产环境中工作得非常好。 为了在开发中模拟相同的场景,我可以克服第一个依赖项, 但我该如何克服第二个呢?

/* 具有解决方法的开发示例 */

  <?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");
        }
    ?>

如何安装临时证书用于开发目的? 或者以某种方式伪造环境。

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 .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪异←思 2024-12-17 16:44:24

您可以创建自己的可在开发中使用的证书。创建证书的机制因平台而异。以下是一篇有关如何在 Windows 上使用 XAMPP 创建一个的文章:

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

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文