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
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.

Link to comment
Share on other sites

  • 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));

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.