醉菜鸟 2021-08-03 14:43:01

php 判断是否是https访问

/**
* 当前是否ssl
* @return bool
*/
function is_ssl()
{
if (isset($_SERVER['HTTPS']) && ('1' == $_SERVER['HTTPS'] || 'on' == strtolower($_SERVER['HTTPS']))) {
return true;
} elseif (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && 'on' == strtolower($_SERVER['HTTP_FRONT_END_HTTPS'])) {
return true;
} elseif (isset($_SERVER['HTTP_X_CLIENT_SCHEME']) && 'https' == $_SERVER['HTTP_X_CLIENT_SCHEME']){
return true;
} elseif (isset($_SERVER['REQUEST_SCHEME']) && 'https' == $_SERVER['REQUEST_SCHEME']) {
return true;
} elseif (isset($_SERVER['SERVER_PORT']) && '443' == $_SERVER['SERVER_PORT']) {
return true;
} elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO']) {
return true;
}
return false;
}
意见反馈