Skip to content

Instantly share code, notes, and snippets.

@nasal
Created October 6, 2014 10:08
Show Gist options
  • Save nasal/27821ba69b0fda8484dd to your computer and use it in GitHub Desktop.
Save nasal/27821ba69b0fda8484dd to your computer and use it in GitHub Desktop.
PHP: Force SSL
<?php
if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') {
if(!headers_sent()) {
header("Status: 301 Moved Permanently");
header(sprintf(
'Location: https://%s%s',
$_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI']
));
exit();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment