使用PHP检测SSL [英] Detecting SSL With PHP

查看:113
本文介绍了使用PHP检测SSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何在不使用$ _SERVER ['HTTPS']的情况下使用HTTPS

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆