【FastAdmin插件】增加获取域名方法

vendor\fastadminnet\fastadmin-addons\src\common.php
function addon_domain()
{
    $request = think\Request::instance();
    $hostname = $request->host();
    $port = $request->port();
    $scheme = $request->scheme();
    
    // 判断是否为非标准端口
    $isStandard = ($scheme == 'http' && $port == 80) || ($scheme == 'https' && $port == 443);
    
    if ($isStandard) {
        $domain = $hostname;
    } else {
        $domain = $hostname . ':' . $port;
    }
    
    // 最终完整 URL 前缀
    $urlPrefix = $scheme . '://' . $domain;
    return $urlPrefix;
}

发表评论