Check if HTTPS is on in PHP

/ Published in: PHP
Save to your folder(s)

This 'Check if HTTPS is on in PHP' script accounts for servers which set HTTPS differently. Some servers do not set HTTPS, others set it to 'off', etc. Only checking if HTTPS is on will cause an 'undefined index error' in these cases.

Copy this code and paste it in your HTML
  1. if (isset($_SERVER['HTTPS']) &&
  2. strtolower($_SERVER['HTTPS']) == 'on') {
  3. $protocol = 'https://';
  4. } else {
  5. $protocol = 'http://';
  6. }

URL: check_if_https_is_on_in_php

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.