可能的重复:
如何确定是否使用 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模板网!
MySQLi准备好的语句&foreach 循环MySQLi prepared statement amp; foreach loop(MySQLi准备好的语句amp;foreach 循环)
mysqli_insert_id() 是从整个服务器还是从同一用户获Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是从整个服务器还是从同一用户获取记录?)
PHP MySQLi 无法识别登录信息PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 无法识别登录信息)
mysqli_select_db() 需要 2 个参数mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 个参数)
Php mysql pdo 查询:用查询结果填充变量Php mysql pdo query: fill up variable with query result(Php mysql pdo 查询:用查询结果填充变量)
MySQLI 28000/1045 用户“root"@“localhost"的访问MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用户“root@“localhost的访问被拒绝)