問題描述
可能的重復:
如何確定是否使用 HTTPS$_SERVER['HTTPS']
我在網上四處尋找檢測服務器是否使用 HTTPS 連接的方法,但似乎沒有一個站點擁有所有的答案(以及一些不同的答案).檢測服務器是否使用與 PHP 的 HTTPS 連接的所有方法究竟是什么?我需要知道幾種檢測 SSL 的方法,因為我的一些腳本被重新分發,并且不同的服務器處理事情的方式不同.
I went looking around the web for ways to detect if a server is using an HTTPS connection, but no one site seemed to have all the answers (and some different ones). What exactly are all the ways to detect if a server is using an HTTPS connection with PHP? I need to know several ways to detect SSL as some of my scripts are redistributed and various servers handle things differently.
推薦答案
$_SERVER['HTTPS']
如果腳本是通過 HTTPS 協議查詢的,則設置為非空值.
注意:請注意,在 IIS 中使用 ISAPI 時,如果請求不是通過 HTTPS 協議發出的,則該值將 off.
Set to a non-empty value if the script was queried through the HTTPS protocol.
Note: Note that when using ISAPI with IIS, the value will be off if the request was not made through the HTTPS protocol.
http://www.php.net/manual/en/reserved.variables.server.php
因此,這樣做:
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
// SSL connection
}
這篇關于用 PHP 檢測 SSL的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!