[英]switching a page from http to https for secured payment
使用jQuery,我嘗試重定向到https,如下所示
webroot = webroot.replace("http","https");
window.location.href = webroot+"/processpayment";
這在Live中不起作用,但在Dev環境中效果很好。
我嘗試的另一個選項是重定向后端代碼(PHP)。 頁面加載(processpayment / index.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頁面,然后使用
header(“ Location:”。“ https://”。$ appurl);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.