How I resolved an SSL issue retrieving files with PHP

Steve Sohcot
1 min readOct 10, 2020

--

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.

Like this style of writing? 👍👍 Interested in creating a PHP web application and already know what a “variable” is and the concept of an “if” statement? Check out my book: Web Development for Intermediate Programmers — with PHP

--

--

No responses yet