Using PHP to detect SSL per page

If you’ve ever run a site which uses an SSL certificate, you may have found a problem when your site calls information (images perhaps) from a third-party website which does not use an SSL certificate. The user’s web-browser will often display an icon or some other form of indication that part of the transaction is no-longer encrypted.

Ideally you want to avoid calling the external content on any page which is SSL secured or rather (for the purposes of this statement) only call the content when on a non SSL secured page.

Thankfully, if you’re using Apache and PHP, you’re on to a winner. The following statement checks with Apaches as to whether the current page is being served as HTTPS or not and renders the page with or without the third-party content as appropriate.

<?php  if ($_SERVER[‘HTTPS’] != “on”) { echo ‘this is where you make HTML calls to your external content”;}  ?>

This should hopefully get rid of those pesky browser warnings for your dynamic pages.