php如何判断HTTP请求是否为https
2020-02-28 本文已影响0人
耶古铁
/**
* 判断当前请求是否为https
* @return bool
*/
private function isHttps()
{
if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
return true;
}
if (isset($_SERVER['HTTP_ORIGIN']) && (strpos($_SERVER['HTTP_ORIGIN'], 'https://') === 0)) {
return true;
}
if (isset($_SERVER['HTTP_REFERER']) && (strpos($_SERVER['HTTP_REFERER'], 'https://') === 0)) {
return true;
}
return false;
}