How I resolved an SSL issue retrieving files with PHP

For my “secure” site, the “lock” icon was broken in the search bar. Using Google Chrome, I found there were some resources being loaded that were not secure.

One was a picture from Amazon AWS. Another was a jQuery plugin that was being pulled from a CDN.

The solutions

Use PHP to detect if the user is viewing your site over an HTTPS connection:

<?php if ($_SERVER['HTTPS'] != "on") { ?>

When displaying the image, I just use the HTTPS version as needed.

This would apply for the sites that do NOT have the option of “always display over HTTPS”.

For the jQuery CDN, they didn’t have an SSL version available. I copied the file and put it on my web server. While this defeats the purpose of a CDN, at least the site is now considered secure.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store