Skip to content

Instantly share code, notes, and snippets.

@pweinzettel
Created August 4, 2020 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pweinzettel/9930c942a4d43fc33bcbd340416ce00b to your computer and use it in GitHub Desktop.
Save pweinzettel/9930c942a4d43fc33bcbd340416ce00b to your computer and use it in GitHub Desktop.
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