编程语言
首页 > 编程语言> > php获取用户真实IP和防刷机制(绕过cdn的ip)

php获取用户真实IP和防刷机制(绕过cdn的ip)

作者:互联网

如何获取用户IP地址

public static function getClientIp()
    {
        if (getenv('HTTP_CLIENT_IP')) {
            $ip = getenv('HTTP_CLIENT_IP');
        }
        if (getenv('HTTP_X_REAL_IP')) {
            $ip = getenv('HTTP_X_REAL_IP');
        } elseif (getenv('HTTP_X_FORWARDED_FOR')) {
            $ip = getenv('HTTP_X_FORWARDED_FOR');
            $ips = explode(',', $ip);
            $ip = $ips[0];
        } elseif (getenv('REMOTE_ADDR')) {
            $ip = getenv('REMOTE_ADDR');
        } else {
            $ip = '0.0.0.0';
        }

        return $ip;
    }

文章来源:https://cloud.tencent.com/developer/article/1367135

标签:REAL,防刷,HTTP,FORWARDED,IP,cdn,getenv,ip
来源: https://www.cnblogs.com/weilianguang/p/11297505.html