coffee_cn

博客园 首页 新随笔 联系 订阅 管理
function get_cert_info($domain){
    $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;
}
$domain = 'www.baidu.com';
$cert_info = get_cert_info($domain);
$validTo_time_t = $cert_info['validTo_time_t'];
$validTo_time_d = date('Y-m-d H:i:s', $validTo_time_t);
echo($validTo_time_d);

 

posted on 2019-11-21 10:50  coffee  阅读(874)  评论(0编辑  收藏  举报