Created
August 4, 2020 16:51
-
-
Save pweinzettel/9930c942a4d43fc33bcbd340416ce00b to your computer and use it in GitHub Desktop.
Simple SSL web cert check from PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"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