I have some code that makes a connection to public websites and returns information about the SSL certificate - code is working perfectly fine.
I would like to add an if statement where if the connection could not be established then it would return "could not establish connection".. right now, if it cannot connect it produces a whole heap of warnings.
The code responsible for making the socket connection is as follows
MAKE SOCKET CONNECTION
$ctx = stream_context_create( array("ssl" => $ssloptions) );
$result = stream_socket_client("ssl://$url:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $ctx);
$cont = stream_context_get_params($result);
IF SOCKET CONNECTION FAILED
echo "could not establish connection"
IF CONNECTION SUCCESSFUL
foreach($cont["options"]["ssl"]["peer_certificate_chain"] as $cert) {
openssl_x509_export($cert, $pem_encoded);
echo $pem_encoded;
}
Appreciate the assistance.