<?php
//查询入口
function testOp($domain){
$cert_info = get_cert_info($domain);
$dn = $cert_info['subject']['CN']; //证书保护域名
$validFrom_time_t = date('Y-m-d H:i:s', $cert_info['validFrom_time_t']); //证书开始时间
$validTo_time_d = date('Y-m-d H:i:s', $cert_info['validTo_time_t']); //证书结束时间
if($cert_info['validTo_time_t']){
//echo "+-证书保护域名:" . $dn . " -+------------------+n";
//echo "+-证书开始时间:" . $validFrom_time_t . " -+------------------+n";
//echo "+-证书结束时间:" . $validTo_time_d . " -+------------------+n";
//echo $cert_info['validTo_time_t'];
//echo '<pre>';print_r($cert_info);
return $cert_info['validTo_time_t'];
}else{
return false;
}
}
function get_cert_info($domain){
set_time_limit(100);
$context = stream_context_create(['ssl' => [
'capture_peer_cert' => true,
'capture_peer_cert_chain' => true,
],
]);
$client = @stream_socket_client("ssl://".$domain.":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
if($client==false) {
return false;
}
$params = stream_context_get_params($client);
$cert = $params['options']['ssl']['peer_certificate'];
$cert_info = openssl_x509_parse($cert);
return $cert_info;
}
$time = testOp("www.kekc.cn");
echo $time;
© 版权声明
THE END
暂无评论内容