Jump to content

Certificate Expiration for Remote Server


IsmAvatar

Recommended Posts

I've been looking for a function or a couple of functions which will allow me to get the Certificate Expiration date for a given website. I've tried openSSL, but their functions only seem to work on the current server, which is useless to me because my server doesn't allow SSL or certificates. I just want the certificate of an external website, e.g. www.gna.org has a certificate (signed by themselves, but a certificate nonetheless).

I've also tried cURL, since that allows you to access a remote server, but that will just check their certificate - it doesn't offer any functionality for e.g. checking when it will expire.

 

This seems like a simple enough question, but I haven't found anything about it anywhere, so I'm asking here.

 

Thanks a bunch in advance,

-IsmAvatar

Link to comment
https://forums.phpfreaks.com/topic/68487-certificate-expiration-for-remote-server/
Share on other sites

Bump

 

This seems like a simple enough thing, I can't imagine why it's not getting any responses.

Let me restate it in simple terms:

I want to check the Certificate, like the SSL certificate, of some website. I want to know the Certificate's Expirtaion Date - when it will expire. But most importantly, this can't just be *my* server, it must be a "remove" server, that is, one that is outside of the scope of the server that is running the php script. Like if I run my script on Google (just an example), but I want to get the Certificate of Sun's webpage, so that I can see when it will expire.

  • 3 years later...
$host = 'www.example.com';
$context = stream_context_create(array('ssl' => array('capture_peer_cert' => TRUE)));
$html = file_get_contents('https://'.$host, NULL, $context);
$opts = stream_context_get_options($context);
$ssl = openssl_x509_parse($opts['ssl']['peer_certificate']);
$expdate = DateTime::createFromFormat('ymd', substr($ssl['validTo'], 0, 6));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.