问题描述
我需要检查给定网站的 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"]);
- PHP:stream_context_create
- PHP:stream_socket_client
- PHP:stream_context_get_params
此时您需要使用 OpenSSL 来处理证书信息.您可以在 PHP 手册中阅读有关 OpenSSL 的内容.
You'll then need to use OpenSSL to work the the certificate information at this point. You can read about OpenSSL in the PHP manual.
这篇关于需要检查网站是否包含 ssl 证书,如果是,那么使用 php 脚本的证书的到期日期是多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!