Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2

Thread: Ip code help?

  1. #1
    Junior Member
    Join Date
    Jan 2016
    Posts
    1
    Member #
    53036

    Exclamation Ip code help?

    **I AM USING MYBB**

    Hello,

    So this is going to be a odd question.. Now this has been an issues for almost a year now, when I first started my forum. It is now near completion and I am trying to finish the odds and ends I left for later.

    First off, my forum is for my xbox clan and my minecraft server, so I m running it off of a virtual machine with XAMPP. I have everything working alright but the IP. At first the IP's were all the same, coming up to the local address, 10.0.2.2, and then I was reading online trying to find new get_ip codes thinking that was the issue. After a few days trying to figure it out, I just added more IP registration allowed in a day for the time being. Today I am back at it and tryign to find solutions. I read online that it was supposed to be a init.php issue or something and I should put the following code under <?php

    Code:
    Code:
    $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];

    But all that did was put a big gap on the header of my forum. I tried placing this code a bit lower on and it didnt change anything BUT, the IP changed from 10.0.2.2 to, "unknown" So I am assuming I am somewhat on the right track? My get_ip code from the functions.php goes as followed:
    Code:
    Code:
    function get_ip()
     {
         global $mybb, $plugins;
     
         $ip = strtolower($_SERVER['REMOTE_ADDR']);
     
         if($mybb->settings['ip_forwarded_check'])
         {
             $addresses = array();
     
             if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
             {
                 $addresses = explode(',', strtolower($_SERVER['HTTP_X_FORWARDED_FOR']));
             }
             elseif(isset($_SERVER['HTTP_X_REAL_IP']))
             {
                 $addresses = explode(',', strtolower($_SERVER['HTTP_X_REAL_IP']));
             }
     
             if(is_array($addresses))
             {
                 foreach($addresses as $val)
                 {
                     $val = trim($val);
                     // Validate IP address and exclude private addresses
                     if(my_inet_ntop(my_inet_pton($val)) == $val && !preg_match("#^(10\.|172\.(1[6-9]|2[0-9]|3[0-1])\.|192\.168\.|fe80:|fe[c-f][0-f]:|f[c-d][0-f]{2}:)#", $val))
                     {
                         $ip = $val;
                         break;
                     }
                 }
             }
         }
     
         if(!$ip)
         {
             if(isset($_SERVER['HTTP_CLIENT_IP']))
             {
                 $ip = strtolower($_SERVER['HTTP_CLIENT_IP']);
             }
         }
     
         if($plugins)
         {
             $ip_array = array("ip" => &$ip); // Used for backwards compatibility on this hook with the updated run_hooks() function.
             $plugins->run_hooks("get_ip", $ip_array);
         }
     
        return $ip;
     }
    I've also tried using,
    Code:
    function get_ip()
    {
    	global $mybb, $plugins;
    	$ip = 0;
    	if(!preg_match("#^(10|172\.(1[6-9]|2[0-9]|3[0-1])|192\.168)\.#", $_SERVER['REMOTE_ADDR']))
    	{
    		$ip = $_SERVER['REMOTE_ADDR'];
    	}
    	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);
    		}
    		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;
    				}
    			}
    		}
    	}
    	if(!$ip)
    	{
    		if(isset($_SERVER['HTTP_CLIENT_IP']))
    		{
    			$ip = $_SERVER['HTTP_CLIENT_IP'];
    		}
    	}
    	if($plugins)
    	{
    		$ip_array = array("ip" => &$ip); // Used for backwards compatibility on this hook with the updated run_hooks() function.
    		$plugins->run_hooks("get_ip", $ip_array);
    	}
    	return $ip;
    }
    But come back with the same "unknown IP...

    Also, yes my "Scrutinize User's IP address?" is at yes and first option is at auto. That was the first thing I tried.

    Thank you.
    Last edited by kilek; Jan 15th, 2016 at 08:08 PM.

  2.  

  3. #2
    Member DerrickE's Avatar
    Join Date
    Jul 2007
    Location
    Houston, TX
    Posts
    58
    Member #
    15580
    Liked
    10 times
    It may be an issue with how your apache is setup. It may not be properly setting the server variables before passing them off to PHP.

    Try outputting these to see if they contain the actual IP address of the visitor:
    $_SERVER['REMOTE_ADDR']
    $_SERVER['HTTP_X_REAL_IP'];
    $_SERVER['HTTP_X_FORWARDED_FOR']
    $_SERVER['HTTP_CLIENT_IP']

    If they do, then you should be getting an IP address back instead of unknown and we can work on debugging the script.
    If they don't, then we need to look at your apache configuration to see why it's not passing the correct IP.
    Or as you are running it off a VM, the network connection itself may not passing the incoming IP correctly and everything will be localhost.

    But check the output of those variables first to start with and we can go from there.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:07 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com