Is is possible to get the details like if a domain (say www.example.com
) is HTTPS ready?
I need to validate some URLs, whether they have SSL certificate or not. I know, by using $_SERVER['HTTPS']
we can check our server details. but how can I achieve the same for other domains.
Any help would be much appreciated.
There's no way to check if the certificate is secure or not using PHP alone without API (green padlock)
But you can use this, which use a API: https://github.com/spatie/ssl-certificate
Finally, I've ended up with the following my code:
$stream = stream_context_create (array("ssl" => array("capture_peer_cert" => true)));
$read = fopen("https://www.example.com", "rb", false, $stream);
$cont = stream_context_get_params($read);
$var = ($cont["options"]["ssl"]["peer_certificate"]);
$result = (!is_null($var)) ? true : false;
If HTTPS is enabled for a domain, var_dump($var)
gives the output as shown:
resource(4) of type (OpenSSL X.509)
If it doesn't exist it returns NULL
.
I've checked a few domains. It seems to be working fine. I hope it will help someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With