PHP实现网站访客来访显示访客IP&浏览器&操作系统

代码

function getOs() {
    if (!empty($_SERVER[‘HTTP_USER_AGENT‘])) {
        $os = $_SERVER[‘HTTP_USER_AGENT‘];
        if (preg_match(‘/win/i‘, $os)) {
            $os = ‘Windows‘;
        } elseif (preg_match(‘/mac/i‘, $os)) {
            $os = ‘MAC‘;
        } elseif (preg_match(‘/linux/i‘, $os)) {
            $os = ‘Linux‘;
        } elseif (preg_match(‘/unix/i‘, $os)) {
            $os = ‘Unix‘;
        } elseif (preg_match(‘/bsd/i‘, $os)) {
            $os = ‘BSD‘;
        } else {
            $os = ‘Other‘;
        }
        return $os;
    } else {
        return "获取访客操作系统信息失败!";
    }
}

function getBrowser() {
    if (!empty($_SERVER[‘HTTP_USER_AGENT‘])) {
        $br = $_SERVER[‘HTTP_USER_AGENT‘];
        if (preg_match(‘/MSIE/i‘, $br)) {
            $br = ‘MSIE‘;
        } elseif (preg_match(‘/Firefox/i‘, $br)) {
            $br = ‘Firefox‘;
        } elseif (preg_match(‘/Chrome/i‘, $br)) {
            $br = ‘Chrome‘;
        } elseif (preg_match(‘/Safari/i‘, $br)) {
            $br = ‘Safari‘;
        } elseif (preg_match(‘/Opera/i‘, $br)) {
            $br = ‘Opera‘;
        } else {
            $br = ‘Other‘;
        }
        return $br;
    } else {
        return "获取浏览器信息失败!";
    }
}
 
//获取ip
function getIp() {
    if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP") , "unknown")) {
        $ip = getenv("HTTP_CLIENT_IP");
    } else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR") , "unknown")) {
        $ip = getenv("HTTP_X_FORWARDED_FOR");
    } else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR") , "unknown")) {
        $ip = getenv("REMOTE_ADDR");
    } else if (isset($_SERVER[‘REMOTE_ADDR‘]) && $_SERVER[‘REMOTE_ADDR‘] && strcasecmp($_SERVER[‘REMOTE_ADDR‘], "unknown")) {
        $ip = $_SERVER[‘REMOTE_ADDR‘];
    } else {
        $ip = "unknown";
    }
    return $ip;
}

PHP实现网站访客来访显示访客IP&浏览器&操作系统

上一篇:Thinkphp6中where条件中字段与字段比较条件的写法


下一篇:WebStorm React JS语法报错问题