需要检查网站是否包含 ssl 证书,如果是,那么使用 php 脚本的证书的到期日期是多少 [英] Need To check the website contains ssl certificate or not if yes then what is the expire date of the certificate using php scripts

查看:29
本文介绍了需要检查网站是否包含 ssl 证书,如果是,那么使用 php 脚本的证书的到期日期是多少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查给定网站的 php 脚本是否包含 ssl 证书,如果它包含,那么证书的到期日期是多少.

I need to check with the php scripts to given website contains ssl certificate or not if it contains then what is the expire date of certificate.

有没有办法使用 php 脚本获取任何网站的这些信息?

Is there any way to get this information for any website using php scripts?

如果是,请告诉我.我在谷歌上尝试了很多次,但没有找到任何东西.

If yes, then plzzz let me know. I have tried so many times on google, but I did not find anything.

谢谢.

推荐答案

是的,您应该能够使用 PHP 内置的 stream_socket_client 函数获取证书信息.

Yes, you should be able to get certificate information by using the stream_socket_client function built into PHP.

这个特殊的方法效果很好,因为它实际上并不发出 HTTP 请求,所以您不必执行 fopen.

This particular method works nicely because it doesn't actually make an HTTP request so you don't have to do a fopen.

$get = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE)));
$read = stream_socket_client("ssl://www.google.com:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get);
$cert = stream_context_get_params($read);
var_dump($cert["options"]["ssl"]["peer_certificate"]);

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆