A Perhaps Useful PHP Snippet for Those Who Use Amazon Ads (and Possibly Others)

Amazon is their own Certificate Authority. Unfortunately, that doesn’t stop them from letting the SSL certificates on their ad servers expire for a week or so every three months, which causes the ads not to render.

During a recent instance, I threw little code snippet together. All it does is check the certificate’s validity and assigns the result as $isValid.

$ch = curl_init('https://z-na.amazon-adsystem.com');
curl_setopt($ch, CURLOPT_CONNECT_ONLY, true);
if(curl_exec($ch) === false) { $isValid = 0; }
else { $isValid = 1; }

I use the result to select alternate ads (or simply collapse the DIV) if the certificate is expired. But all it actually does is check whether a certificate is valid, and can be used for any purpose where that information is important.

I know there are other ways to do this (openssl_x509_parse, for example), but this seems easier and lower-resource when the only question that needs to be answered is whether the cert is valid, not any of the other details. By default, the curl request will fail if the cert is invalid for any reason, which answers that one question.


This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.