I have a code that checks if a website have SSL certificate as you can see below:
$url = "stackoverflow.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']);
var_dump($certinfo);
If I insert a url that contains HTTPS, this code return to me all the information about the certificate, but if I insert a url that doesn't contain HTTPS I receive the following error:
Warning: stream_socket_client (): Unable to connect to ssl: //: 443 (No connection could be made because the target machine actively refused it.) In
How I can solve this problem?