简体   繁体   English

用php阻止代理用户的更好方法

[英]Better way to block proxy users with php

Actually, i'm using this method to block proxy users. 实际上,我正在使用这种方法来阻止代理用户。

<?php if(@fsockopen($_SERVER['REMOTE_ADDR'], 80, $errstr, $errno, 1))
die("Access not allowed for proxy users."); ?>

Have you a better way for that? 您有更好的方法吗? this method is good, but block VPN users and think it can block google bots.. 这种方法不错,但是可以阻止VPN用户,并认为它可以阻止Google机器人。

I'm not aware of a bulletproof way to do this, but this would be pretty much complete: 我不知道这样做的防弹方法,但这几乎是完整的:

if (get_ip_address() !== get_ip_address(true))
{
echo 'using proxy';
}

This get_ip_address() function was adapted from this answer and goes as follows: 此get_ip_address()函数改编自此答案,其内容如下:

function get_ip_address($proxy = false)
{
if ($proxy === true)
{
    foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED',     'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED') as $key)
    {
        if (array_key_exists($key, $_SERVER) === true)
        {
            foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip)
            {
                if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false)
                {
                    return $ip;
                }
            }
        }
    }
}

return $_SERVER['REMOTE_ADDR'];

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM