如何从访客获得真实IP?

如何从访客获得真实IP?,第1张

如何从访客获得真实IP?

试试这个PHP代码

<?PHPfunction getUserIP(){    // Get real visitor IP behind CloudFlare network    if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {   $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];   $_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"];    }    $client  = @$_SERVER['HTTP_CLIENT_IP'];    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];    $remote  = $_SERVER['REMOTE_ADDR'];    if(filter_var($client, FILTER_VALIDATE_IP))    {        $ip = $client;    }    elseif(filter_var($forward, FILTER_VALIDATE_IP))    {        $ip = $forward;    }    else    {        $ip = $remote;    }    return $ip;}$user_ip = getUserIP();echo $user_ip; // Output IP address [Ex: 177.87.193.134]?>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5045645.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存