php判断当前访问地址的访问协议是否是https

2019-03-17T11:00:00
/**
 * 判断当前访问地址的访问协议是否是https
 *
 * @para string $string
 *
 * @return string
 */
if (!function_exists('is_https')) {
    function is_https() {
        // return ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? TRUE : FALSE; 
        if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) {
            return TRUE;
        }elseif (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') {
            return TRUE;
        } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
            return TRUE;
        } elseif (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) != 'off') {
            return TRUE;
        }
        return FALSE;
    }
}
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »