[Pushed] [Feature Request] Add new x-remote-addr var to the get_ip() function
#1
We were having problems with user registration because all user IP was being registered as 127.0.0.1.

Then, after ask here, in the SourceForge and burn the brain a little I looked for some informations in the Admin CP and then I found the PHP Info. There I was able to see that SourceForge doesn't use the HTTP_X_FORWARDED_FOR and HTTP_X_REAL_IP as an alternative to REMOTE_ADDR as implemented in the get_ip() function - they use HTTP_X_REMOTE_ADDR.

So, the solution was to add it to the IP check in the file ./inc/functions.php, function get_ip():

Quote:    :
    if($mybb->settings['ip_forwarded_check'])

    {
        if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        {
            preg_match_all("#[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}#s", $_SERVER['HTTP_X_FORWARDED_FOR'], $addresses);
        }
        elseif(isset($_SERVER['HTTP_X_REAL_IP']))
        {
            preg_match_all("#[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}#s", $_SERVER['HTTP_X_REAL_IP'], $addresses);
        }
        elseif(isset($_SERVER['HTTP_X_REMOTE_ADDR']))
        {
            preg_match_all("#[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}#s", $_SERVER['HTTP_X_REMOTE_ADDR'], $addresses);
        }

        if(is_array($addresses[0]))
        {
            foreach($addresses[0] as $key => $val)
            {
                if(!preg_match("#^(10|172\.(1[6-9]|2[0-9]|3[0-1])|192\.168)\.#", $val))
                {
                    $ip = $val;
                    break;
                }
            }
        }
    }
    :

It would be nice see this fix added in the future version of MyBB.

p.s. the original thread
Reply


Messages In This Thread
[Feature Request] Add new x-remote-addr var to the get_ip() function - by Micheus - 2015-02-17, 03:37 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)