Created
April 22, 2013 22:19
-
-
Save iloris/5439056 to your computer and use it in GitHub Desktop.
PHP SSL redirection
This file contains 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 | |
function is_ssl() { | |
if ( isset($_SERVER['HTTPS']) ) { | |
if ( 'on' == strtolower($_SERVER['HTTPS']) ) | |
return true; | |
if ( '1' == $_SERVER['HTTPS'] ) | |
return true; | |
} elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { | |
return true; | |
} | |
if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https' ) { | |
return true; | |
} | |
return false; | |
} |
Just curious, what is the advantage of using this over redirecting the whole site to HTTPS?
You can use this on the whole site to https but the advantage is that it's easier to configure than htaccess, if someone visit the website without https, he will be redirected to the https version, you don't need to hardcode the domain name in the htaccess so it's also easier for locahost testing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use like this :