本文介绍了如何从 PHP 中的 SSL 证书文件中获取到期日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从 SSL 证书文件中获取到期日期.我创建了一个 PHP 网页,用户可以在其中上传他的 SSL 证书文件,我必须使用 PHP 获取该文件的到期日期.
解决方案
下面的代码应该会有所帮助:
$url = "https://www.google.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']);echo '
';打印_r($certinfo);echo '</pre>';
到期日期应在 $certinfo['validTo'] 字段下.
I want to get the expiry date from the SSL Certificate file. There is a web page in PHP that I've created, in which user can upload his SSL Certificate file and I will have to get the expiry date of that file using PHP.
解决方案The code below should help:
$url = "https://www.google.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']); echo '<pre>'; print_r($certinfo); echo '</pre>';
The expiry date should be under $certinfo['validTo'] field.
这篇关于如何从 PHP 中的 SSL 证书文件中获取到期日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!