Easy way to check if HTTPS / SSL is being loaded (PHP)

<?php 

function httpscheck($url = '')
{
  if($_SERVER['HTTPS'] != "on" || $_SERVER['HTTP_PORT'] != 443)
  {
    if(strlen($url) == 0)
    {
      $url = $_SERVER['REQUEST_URI'];
    }
    if(headers_sent())
    {
      trigger_error('SSL redirect failed as HTTP headers were previously sent to the browser', E_NOTICE);
    }
    else
    {
      die(header('Location: ' . $url));
    }
  }
}

October 21, 2011 at 3:55am / Code, PHP 

Comments On This Entry

I'm out of league here. Too much brain power on dpislay!

Vinnie @ 08:54:11 AM, Sunday, October 23, 2011

Compose New Blog Comment
    required = required field         warning HTML and URL's are not allowed

[back to main]