0

OpenSSL 1.1.1 php enabled for apache

all sites give me "1970-01-01" as an expiry date

<?php

$websites = $_POST['websites'];
$websites = explode(',', $websites);

foreach ($websites as $website) :
    $website = trim($website);
    $cert = openssl_x509_parse(file_get_contents("https://{$website}"));
    $expiration = date('Y-m-d', $cert['validTo_time_t']);
    echo "{$website}: {$expiration}<br>";
endforeach;

?>

any site gives the same date

1 Answers1

0

You are passing the contents (HTML) of the site to openssl_x509_parse:

$cert = openssl_x509_parse(file_get_contents("https://{$website}"));

You either need and certificate object or the contents of the actual certificate

 openssl_x509_parse(OpenSSLCertificate|string $certificate, bool $short_names = true): array|false

https://www.php.net/manual/en/function.openssl-x509-parse.php

See: How to get SSL certificate info with CURL in PHP? for an example.