如何检查域是否有SSL证书? [英] How to check if domain has SSL certificate or not?
问题描述
是否可以获取详细信息,例如域名(例如 www.example.com
)是否已准备好HTTPS?
Is is possible to get the details like if a domain (say www.example.com
) is HTTPS ready?
我需要验证一些URL,无论他们是否有SSL证书。我知道,通过使用 $ _ SERVER ['HTTPS']
,我们可以查看服务器详细信息。但我怎样才能在其他领域实现同样的目标。
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.
推荐答案
最后,我最终得到了以下代码:
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;
如果为域启用了HTTPS, var_dump($ var)
给出输出,如下所示:
If HTTPS is enabled for a domain, var_dump($var)
gives the output as shown:
resource(4) of type (OpenSSL X.509)
如果它不存在则返回 NULL
。
我查了几个域名。它似乎工作正常。我希望它会帮助别人。
I've checked a few domains. It seems to be working fine. I hope it will help someone.
这篇关于如何检查域是否有SSL证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!