Skip to content

Instantly share code, notes, and snippets.

@Kaweechelchen
Created January 27, 2016 06:32
Show Gist options
  • Save Kaweechelchen/712f0a97800f24aaf012 to your computer and use it in GitHub Desktop.
Save Kaweechelchen/712f0a97800f24aaf012 to your computer and use it in GitHub Desktop.
script to get the expiry date of the SSL cert of a specific domain
<?php
date_default_timezone_set('Europe/Luxembourg');
$expiryDate = getCertExpiryDate('mona.lu');
if ($expiryDate) {
echo date('r', $expiryDate );
}
function getCertExpiryDate($domain) {
$get = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE)));
$read = stream_socket_client("ssl://$domain:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get);
$cert = stream_context_get_params($read);
$certinfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate'], true);
if (strpos($certinfo['extensions']['subjectAltName'], $domain)) {
return $certinfo['validTo_time_t'];
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment