PHP判断http、https协议方法

封装函数如下:

function getServerSchema(){
    if ( (!empty($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] == 'https') || (! empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (! empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') ) {
       return 'https';
    }
    return 'http';
}

 

你可能感兴趣的:(PHP)