PHP获取SSL信息

<?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.vience.cn");
echo $time;
© 版权声明
THE END
喜欢就支持一下吧
点赞0赞赏
分享
评论 抢沙发
奇乐科技的头像-奇乐博客

昵称

取消
昵称表情代码图片