本文介紹了使用 PHP 從 HTTP 重定向到 HTTPS的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我在一個(gè)購物車網(wǎng)站上工作,我想在用戶輸入賬單詳細(xì)信息時(shí)將用戶重定向到 HTTPS 頁面,并在他退出之前保持下一頁的 HTTPS 連接.
I'm working on a shopping cart website and I would like to redirect the user to a HTTPS page when he's entering his billing details and maintain the HTTPS connection for the next pages until he logs out.
我需要在服務(wù)器上安裝什么(我使用的是 Apache)才能執(zhí)行此操作,以及如何從 PHP 完成此重定向?
What do I need to install on the server (I'm using Apache) in order to do this, and how can this redirect be done from PHP?
推薦答案
嘗試這樣的事情(應(yīng)該適用于 Apache 和 IIS):
Try something like this (should work for Apache and IIS):
if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === "off") {
$location = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $location);
exit;
}
這篇關(guān)于使用 PHP 從 HTTP 重定向到 HTTPS的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!