Last active
January 16, 2019 16:11
-
-
Save kobus1998/fac0ceb772f09bd2aa26d3fd3515d3f8 to your computer and use it in GitHub Desktop.
Force https PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Force to redirect to https | |
* | |
* @return void | |
*/ | |
function forceHttps() | |
{ | |
// check already https | |
if (isset($_SERVER['https']) && $_SERVER['https'] != null) return; | |
// check local | |
if (strpos($_SERVER['HTTP_HOST'], 'localhost') !== false) return; | |
header("HTTP/1.1 301 Moved Permanently"); | |
header("Reason: HTTPS"); | |
header("Location: https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"); | |
die; | |
}; | |
forceHttps(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment