PHP获取当前网址域名


function getHttpProtocol()
{
    $protocol = 'http';
    if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
        $protocol = 'https';
    } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
        $protocol = 'https';
    } elseif (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
        $protocol = 'https';
    }
    return $protocol;
}
echo getHttpProtocol().'://'.$_SERVER['HTTP_HOST'];

发表评论

邮箱地址不会被公开。 必填项已用*标注