Skip to content

Instantly share code, notes, and snippets.

@codehooligans
Created June 30, 2016 13:41
Show Gist options
  • Save codehooligans/91f1b98246ed142db10131f81712cdb2 to your computer and use it in GitHub Desktop.
Save codehooligans/91f1b98246ed142db10131f81712cdb2 to your computer and use it in GitHub Desktop.
Example PHP code to get SSL cert info
<?php
$url = "http://www.codehooligans.com";
$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']);
echo "certinfo<pre>". print_r($certinfo, true) ."</pre>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment