建立domains.txt文件保存网址,每行一个网址
<?php // Load domain list from domains.txt $domains = explode("\n", file_get_contents('domains.txt')); $domains = array_filter($domains, function($domain) { return $domain !== ''; }); // Get certificate info function getCertificate($domain) { $url = "https://$domain"; $orignal_parse = parse_url($url, PHP_URL_HOST); $get = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE))); $read = stream_socket_client("ssl://".$orignal_parse.":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get); $cert = stream_context_get_params($read); $certinfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate']); return $certinfo; } // Process ceriticate info of each domain $certs = []; foreach ($domains as $domain) { $rawCert = getCertificate($domain); $cert = []; $cert['domain'] = $domain; $cert['validTo'] = gmdate("Y-m-d\ ", $rawCert['validTo_time_t']); $cert['validToUnix'] = $rawCert['validTo_time_t']; $cert['issuer'] = $rawCert['issuer']['CN']; $cert['days'] = (intval($cert['validToUnix']) - time())/60/60/24; $certs[] = $cert; } // Sort by expiring time $validTo = array(); foreach ($certs as $key => $row) { $validTo[$key] = $row['validToUnix']; } array_multisort($validTo, SORT_ASC, $certs); // 标题 echo "<title>hxser 证书检查</title>"; // Generate output $bar = str_repeat('=', 80); $format = "$bar\n %s (%d 天)\n 到期时间: %s 提供商: %s\n$bar\n\n"; $output = ''; foreach ($certs as $cert) { $output .= sprintf($format, $cert['domain'], $cert['days'], $cert['validTo'], $cert['issuer']); } printf("<pre>\n%s\n</pre>", $output); ?>