1. PHP 判断当前协议是否为 HTTPS
function is_https()
{
if ( !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;
}
2. PHP 获取包含网址协议的当前域名
echo domain();
function domain()
{
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https' : 'http';
return $http_type . '://' . $_SERVER['HTTP_HOST'];
}
3. JavaScript 判断当前协议是否为 HTTPS
function is_https()
{
return 'https:' == location.protocol ? true: false;
}
4. JavaScript 获取包含网址协议的当前域名
var domain = location.protocol + '//' + location.host