I'm quite newbie of PHP, but studying and trying to build simple webpage which displays SSL Certificate status. (e.g.Expiry date) Also each servers(common name) and ports are stored at MySQL DB and read by PDO. Usually this works if server returns valid certificate. However it fails to load when certificate is expired or by other reasons such as unmatched Common Name.
Code as below:
<?php
$get = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE)));
$read = stream_socket_client("ssl://".$row["domain"].":".$row["port"], $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get);
$cert = stream_context_get_params($read);
$certinfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate']);
?>
May I be advised how to resolve this issue please?
Thank you!