时间:2021-10-02加入收藏
//查询入口
public function testOp(){
$domain = ''; //网站域名
$cert_info = $this->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']); //证书结束时间
echo "+-证书保护域名:" . $dn . " -+------------------+\n";
echo "+-证书开始时间:" . $validFrom_time_t . " -+------------------+\n";
echo "+-证书结束时间:" . $validTo_time_d . " -+------------------+\n";
echo '<pre>';print_r($cert_info);
}
public 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;
}