08/11/2013 3:01pm

PHP | Solution - Director::is_https() fix


/**

* Return whether the site is running as under HTTPS.
* @param $SSLPortNumber int is equal to SSL port number for server check.
* @return boolean
*/
public static function is_https($SSLPortNumber = null) {
if(isset($_SERVER['HTTP_X_FORWARDED_PROTOCOL'])) {
if(strtolower($_SERVER['HTTP_X_FORWARDED_PROTOCOL']) == 'https') {
return true;
}
}

if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')) {
return true;
}
else if(isset($_SERVER['SSL'])) {
return true;
}

if($SSLPortNumber !== null)
{
if((isset($_SERVER['SERVER_PORT'])) && ($_SERVER['SERVER_PORT'] === $SSLPortNumber))
{
return true;
}
}

return false;
}


Post Comment