Avoid Expired SSL Certificate
Have you experienced your website suddenly giving error messages when you use https:// URLs? Many site owners have.
When that happens, it's almost a certainty that the domain's SSL certificate has expired. It is also almost a certainty that the website owner was unaware of the certificate's expiration date.
The software with this article, SSL Certificate Check, was written to do a quick check on a domain's SSL certificate. The software reports the certificate's expiration date.
SSL Certificate Check will check the certificate expiration date only on domains with a valid certificate. Expired certificates are no longer valid. If you don't have a valid certificate, then you already know something is wrong because https:// URLs don't work.
The interface of the SSL Certificate Check software has been updated several times since 2016. The actual SSL certificate retrieval and parsing have been good since day 1.
It is PHP software. The source code can be uploaded to your server as you find it here. In other words, no customization is required.
There is also a live implementation of the same source code. Test it. Use it to see how it works.
Domain SSL Certificates are publicly available. You can use the software to check SSL expiration dates for your clients. Or any domain.
Type in a domain name (example.com for instance). If the certificate is for a subdomain, then include the subdomain (accounts.example.com or www.example.com for illustration purposes).
Tap the button, and you get the certificate expiration date (assuming there is a valid certificate).
Want more certificate information? Tap the link below the expiration date. You'll end up with all the SSL certificate information that could be found.
Here is the source code.
<?php
/*
SSL Certificate Check
Version 1.3
June 29, 2026
Version 1.0 created May 19, 2016 as SSL Certificate Information
Version 1.1 updated March 25, 2019 with updated interface.
Version 1.2 updated January 8, 2024 was renamed as SSL Certificate Check and has updated interface.
Version 1.3 updated June 29, 2026 with updated interface.
Will Bontrager Software LLC
https://www.willmaster.com/
*/
ini_set('display_errors', 1);
$Information = array();
$CertsCount = 0;
$postURL = '';
$_POST['GET'] = false;
if( empty($_POST['URL']) )
{
if( isset($_GET['URL']) )
{
$_POST['URL'] = $_GET['URL'];
$_POST['GET'] = true;
$_GET = array();
}
else { $_POST['URL'] = ''; }
}
if( preg_match('/\w\.\w/',$_POST['URL']) )
{
$postURL = preg_replace('!^https?://!i','',$_POST['URL']);
$postURL = preg_replace('!/.*$!','',$postURL);
$postURL = "https://$postURL";
$options = array(
CURLOPT_VERBOSE => true,
CURLOPT_CERTINFO => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => false
);
$ch = curl_init($postURL);
curl_setopt_array($ch,$options);
curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch) ;
$Information = curl_getinfo($ch);
curl_close($ch);
$Information['errno'] = $err;
$Information['errmsg'] = $errmsg;
if( isset($Information['redirect_url']) and preg_match('!^https://!i',$Information['redirect_url']) ) { $postURL = $Information['redirect_url']; }
$CertsCount = empty($Information['certinfo']) ? 0 : count($Information['certinfo']);
}
?><!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SSL Certificate Check</title>
<style type="text/css">
* { box-sizing:border-box; }
html, body { font-size:100%; font-family:sans-serif; }
p { line-height:135%; }
h1 { font-size:1.8em; }
h2 { font-size:1.4em; }
a { text-decoration:none; color:#1c5292; font-weight:bold; }
a, a img { border:none; outline:none; }
input { width:100%; font-size:1em; }
input[type='text'] { border:1px solid #ccc; border-radius:5px; padding:4px 6px; }
table { border-collapse:collapse; margin-bottom:1em; }
th { vertical-align:bottom; font-size:.85em; white-space:nowrap; }
td { vertical-align:top; }
.bold { font-weight:bold; }
.content { width:fit-content; position:relative; margin:1in auto; }
.maxwidth { max-width:300px; }
</style>
</head>
<body><div class="content">
<div class="maxwidth">
<div style="position:absolute; left:0px; top:-60px;">
<a href="http://www.willmaster.com/">
<img src="http://www.willmaster.com/images/wmlogo_icon.gif" style="width:50px; height:50px; border:none;" alt="Willmaster logo">
</a>
</div>
<h1>SSL Certificate Check</h1>
</div>
<?php if( count($Information) ): ?>
<div class="maxwidth">
<h2>
Certificate Information
</h2>
<p>
<span class="bold">Domain URL checked:</span><br><?php echo($postURL) ?>
</p>
</div>
<?php if( $Information['errno'] > 0 ): ?>
<div class="maxwidth">
<p>
Error message:<br><?php echo($Information['errmsg']) ?>
</p>
</div>
<?php elseif($_POST['GET']): ?>
<p class="bold">
Certificate<?php if( $CertsCount > 1 ) { echo 's'; } ?> information:
</p>
<?php for( $i=0; $i<$CertsCount; $i++ ) { ?>
<table border="1" cellpadding="7" cellspacing="0">
<tr>
<th colspan="2" style="text-align:left; font-size:115%;">Certificate # <?php echo($i+1); ?></th>
</tr><tr>
<th>Label</th><th style="text-align:left;">Information</th>
</tr>
<?php
foreach( $Information['certinfo'][$i] as $k => $v )
{
list($th['pre'],$th['cancelpre']) = $k == 'Cert' ? ['<pre>','</pre>'] : ['',''];
echo <<<LINE
<tr>
<td>$k</td><td>{$th['pre']}$v{$th['cancelpre']}</td>
</tr>
LINE;
}
?>
</table>
<?php } ?>
<?php else: ?>
<?php if($CertsCount>0): ?>
<?php
$expire = '';
$extime = array();
for( $i=0; $i<$CertsCount; $i++ )
{
foreach( $Information['certinfo'][$i] as $k => $v )
{
if( preg_match('/Expire\s*date/i',$k) )
{
$extime[] = trim($v);
break;
}
}
}
$cnt = count($extime);
for( $i=0; $i<$cnt; $i++ ) { $extime[$i] = strtotime($extime[$i]); }
$expire = date( 'j M Y \a\t G:i:s T', min($extime) );
?>
<p>
<span class="bold">Certificate expires:</span><br><?php echo($expire) ?>
</p>
<p>
<a href="<?php echo($_SERVER['PHP_SELF']) ?>?URL=<?php echo($postURL) ?>">Tap here to get more certificate information.</a>
</p>
<?php else: ?>
<p>
No SSL certificate found.
</p>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<div class="maxwidth" style="border-top:1px solid #333; height:2em;"></div>
<div class="maxwidth">
<form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post">
<p>
Domain name:<br>
<input type="text" name="URL" value="<?php echo($_POST['URL']); ?>">
</p>
<p>
<input type="submit" value="Get Info" style="text-align:left; padding-left:2em;">
</p>
</form>
<p style="width:fit-content; border-top:1px solid #ccc; margin-top:50px;">
Provided by <span style="white-space:nowrap;"><a href="https://www.willmaster.com/">Will Bontrager Software, LLC</a></span>
</p>
</div>
</div>
</body>
</html>
Save the source code to your server as SSLcertcheck.php (or other *.php file name). To use it, type its URL into your browser's address bar.
The SSL Certificate Check software is efficient. It is easy to install and easy to use.
(This content first appeared in Possibilities newsletter.)
Will Bontrager

