PHP - 如何查看服务器是否支持 TLS 1.0? [英] PHP - How to see if a server supports TLS 1.0?
问题描述
我正在编写一个简单的检查器,您可以在其中输入一个 URL,以检查输入的 URL 是否使用 TLS 1.0、1.1 或 1.2.基本上我想显示一条消息,说Yoursite.com 正在使用 TLS 1.0.建议禁用它."
I am writing a simple checker where you can enter a URL that would check if the URL entered is using TLS 1.0, 1.1 or 1.2. Essentially I want to show a message saying "Yoursite.com is using TLS 1.0. It is recommended to disable this."
问题是,如果我是发起呼叫的服务器,我只能弄清楚.然后我可以使用这个.这允许你编写一个 Curl 脚本,连接到 howsmyssl.com,它会返回我用来连接的连接.这不是我想要的.
The problem is, I am only able to figure it out if I am the server making the call. Then I can use this. That allows you to write a Curl script, connect to howsmyssl.com and it would return what connection I used to connect. This is not what I want.
我想知道如何使用 PHP 连接到 URL,并查看该服务器是否支持 TLS1.0、1.1 或 1.2.
I want to know how I can use PHP to connect to a URL, and see if that server supports TLS1.0, 1.1 or 1.2.
有没有办法做到这一点?
Is there a way to do this?
推荐答案
这个怎么样:
<?php
$url = 'https://fancyssl.hboeck.de/';
$protocols = [
'TLS1.0' => ['protocol' => CURL_SSLVERSION_TLSv1_0, 'sec' => false],
'TLS1.1' => ['protocol' => CURL_SSLVERSION_TLSv1_1, 'sec' => false],
'TLS1.2' => ['protocol' => CURL_SSLVERSION_TLSv1_2, 'sec' => true],
'TLS1.3' => ['protocol' => CURL_SSLVERSION_TLSv1_3, 'sec' => true],
];
foreach ($protocols as $name => $value) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSLVERSION, $value['protocol']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch) !== false;
if ($value['sec'] && !$response) {
echo "Secure $name not supported =( \n";
} elseif ($value['sec'] && $response) {
echo "Ok! Secure $name supported \n";
} elseif (!$value['sec'] && $response) {
echo "Insecure $name supported =( \n";
} elseif (!$value['sec'] && !$response) {
echo "Ok! Insecure $name not supported\n";
}
}
输出为:
Ok! Insecure TLS1.0 not supported
Ok! Insecure TLS1.1 not supported
Ok! Secure TLS1.2 supported
Ok! Secure TLS1.3 supported
这篇关于PHP - 如何查看服务器是否支持 TLS 1.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!