//获取站点域名
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;
}

Logo

欢迎加入 MCP 技术社区!与志同道合者携手前行,一同解锁 MCP 技术的无限可能!

更多推荐