Php 如何为开发环境模拟https环境/SSL证书?
我有一个在产品上运行的PHP应用程序,如下所示:Php 如何为开发环境模拟https环境/SSL证书?,php,ssl,https,Php,Ssl,Https,我有一个在产品上运行的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?p
<?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");
}
?>
如何安装用于开发的临时证书?
或者以某种方式伪造环境。您可以创建自己的证书,以便在开发中使用。创建证书的机制因平台而异。下面是一篇关于如何在Windows上使用XAMPP创建的文章: