Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple SSL web cert check from PHP
<?php
$urls = json_decode(file_get_contents('sites.json'),true);
function certdata($url) {
$parseurl = parse_url($url, PHP_URL_HOST);
$get = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE)));
$read = stream_socket_client("ssl://".$parseurl.":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get);
$cert = stream_context_get_params($read);
return openssl_x509_parse($cert['options']['ssl']['peer_certificate']);
}
foreach ($urls as $url) {
echo $url['url'].':'.PHP_EOL;
$cd = certdata($url['url']);
$vleft = (int) (($cd['validTo_time_t']-time())/86400);
echo "> CN: ".$cd['subject']['CN'].PHP_EOL;
echo "> Until: ".date('r',$cd['validTo_time_t']).PHP_EOL;
echo "> Left: ".$vleft." days".PHP_EOL;
echo PHP_EOL;
}
?>
[
{
"url":"https://listmy.link"
},
{
"url":"https://weinzettel.com.ar"
},
{
"url":"https://telegram.com.ar"
},
{
"url":"https://telegram.ar"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment