問題描述
可能的重復(fù):
如何確定是否使用 HTTPS$_SERVER['HTTPS']
我在網(wǎng)上四處尋找檢測(cè)服務(wù)器是否使用 HTTPS 連接的方法,但似乎沒有一個(gè)站點(diǎn)擁有所有的答案(以及一些不同的答案).檢測(cè)服務(wù)器是否使用與 PHP 的 HTTPS 連接的所有方法究竟是什么?我需要知道幾種檢測(cè) SSL 的方法,因?yàn)槲业囊恍┠_本被重新分發(fā),并且不同的服務(wù)器處理事情的方式不同.
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 協(xié)議查詢的,則設(shè)置為非空值.
注意:請(qǐng)注意,在 IIS 中使用 ISAPI 時(shí),如果請(qǐng)求不是通過 HTTPS 協(xié)議發(fā)出的,則該值將 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
}
這篇關(guān)于用 PHP 檢測(cè) SSL的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!