<?php
$url = "http://www.baidu.com";
/**
* Takes a domain name and returns SSL certificate information
*
* @param string $domain_name
* @return array $certinfo
*/
function getSSL($domain_name)
{
$errno = 0;
$errstr = '';
// Set socket connection timeout
$timeout = 30;
// Create a stream context to open a ssl socket
// Set options to get ssl certificate
// https://www.php.net/manual/en/context.php
// https://www.php.net/manual/en/context.ssl.php
$ssl_info = stream_context_create(array(
"ssl" => array(
"capture_peer_cert" => TRUE)));
$stream = stream_socket_client("ssl://" . $domain_name . ":443",
$errno,
$errstr,
$timeout,
STREAM_CLIENT_CONNECT,
$ssl_info);
if (!$stream) {
echo "ERROR: $errno - $errstr";
} else {
$cert_resource = stream_context_get_params($stream);
$certificate = $cert_resource['options']['ssl']['peer_certificate'];
$certinfo = openssl_x509_parse($certificate);
fclose($stream);
return $certinfo;
}
}
print_r(getSSL($url));
?>
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
txttool.com 说一段 esp56物联 查询128 IP查询