ssl证书过期时间检查
作者:admin 发布时间:December 24, 2020 分类:PHP No Comments
可生成泛域名ssl网站
https://freessl.cn/
1 选择多域名通配符
2 选择浏览器方式生成
证书过期时间检查demo
<?php
$g = stream_context_create ([
"ssl" => ["capture_peer_cert" => true],
'http' => [
'method' => 'GET',
'user_agent' => 'shouwang.io ssl detector',
'timeout'=>10
]
]);
$r = fopen("https://range8.cn/", "rb", false, $g);
$cont = stream_context_get_params($r);
$cert = openssl_x509_parse($cont["options"]["ssl"]["peer_certificate"]);
if(empty($cert['validTo_time_t'])) {
throw new \Exception("Can't get cert expire time");
}
$fortyEightHours = strtotime("+48 hours");
if($cert['validTo_time_t'] <= $fortyEightHours) {
throw new \Exception("Cert will expire in 48 hours");
} else {
echo "证书过期时间:", date("Y-m-d H:i:s", $cert['validTo_time_t']);
}