使用PHP检测SSL [英] Detecting SSL With PHP
问题描述
Possible Duplicate:
How To Find Out If You are Using HTTPS Without $_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协议查询。
注意:当使用ISAPI和IIS时,如果请求不是通过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
Ergo,这样做:
Ergo, this'll do:
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
// SSL connection
}
这篇关于使用PHP检测SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!