Reputation: 62
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.
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.
Thanks.
Upvotes: 2
Views: 2905
Reputation: 22967
Yes, you should be able to get certificate information by using the stream_socket_client
function built into PHP.
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"]);
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.
Upvotes: 9