Detecting SSL With PHP(用 PHP 检测 SSL)
问题描述
可能的重复:
如何确定是否使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用 PHP 检测 SSL
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
