Thinkphp封装获取站点https://域名的方法
//获取站点域名
function getSiteUrl(){
$domain = Cache::get('site-domain');
if (empty($domain)) {
$https = isHttps() ? 'https://' : 'http://';
$domain = $https.$_SERVER['HTTP_HOST'];
Cache::set('site-domain',$domain,86400);//缓存一天
}
return $domain;
}
function isHttps(){
if (defined('HTTPS') && HTTPS){return true;}
if (!isset($_SERVER['HTTPS'])){return false;}
if ($_SERVER['HTTPS'] === 1) { //Apache
return true;
} elseif ($_SERVER['HTTPS'] === 'on') { //IIS
return true;
} elseif ($_SERVER['SERVER_PORT'] == 443) { //其他
return true;
}
return false;
}
共有 0 条评论