Force SSL by loading the same page via HTTPS

Just a simple one, I place this in a common file, and then call it at the top of each page that I require to be secured by SSL.

function force_ssl() {
    if ($_SERVER['HTTPS'] != 'on') {
        header("Location: https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
        exit();
    }
}
  • Share/Bookmark

Related posts:

  1. Bash alias to search file contents
  2. MySQL string escaping in PHP

Tags:

Leave a Reply