将页面从 HTTP 切换到 HTTPS 以进行安全支付


switching a page from http to https for secured payment

使用jQuery,我尝试重定向到https,如下所示

webroot  = webroot.replace("http","https");
window.location.href = webroot+"/processpayment";

这在 Live 中不起作用,但在开发环境中运行良好。

我尝试的另一个选项是在后端代码 (PHP) 中重定向。在加载页面(处理付款/索引.php)时,我调用了该函数

http_redirect_https();

该函数执行以下操作

function http_redirect_https(){
if ($_SERVER["HTTPS"] != "on")
{
    header("HTTP/1.1 301 Moved Permanently");    // Optional.
    header("Location: https://{$_SERVER["SERVER_NAME"]}{$_SERVER["REQUEST_URI"]}");
    exit(0); // Ensure that no other code is parsed.
}
}

但这引发了一个错误 - 尝试打开页面的重定向太多。

我卡住了。你能帮忙吗?

你可以使用htaccess或vhost。请尝试以下操作:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

希望这有帮助

我使用类似于您拥有的东西,它工作得很好。

if($_SERVER["HTTPS"] != "on"){
        header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
        exit();
}else{
        header('Strict-Transport-Security: max-age=31536000');
} 

警告:如果将访问者发送到(安全)付款页面的页面使用的是http(而不是https),那么您的网站容易受到SSLSTRIP的攻击

如果您操纵付款信息,那么您真的应该考虑在任何地方使用 https 并激活 HSTS,否则您的访问者不安全。

我可以让它工作的唯一方法是重定向到中间 PHP 页面,然后使用

标头("位置:"."https://".$appurl);