MyBB Community Forums

Full Version: last known ip and registration ip functionality!!!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello, please when i can modify in the catching the visitor ip!? which function?

i explain.. recently i hide my forum behind an nginx reverse proxy server.. for security purposes .. the prb is the mybb take the visitor ip from the $_SERVER['REMOTE_ADDR'] .. so now all the visitors and registrations defined by the proxy ip address .. so i need to do some modification to take the visitor ip from $_SERVER['HTTP_X_FORWARDED_FOR'] .. i dont now where is the functions that responsable for this!?

thanks.
Hi,

maybe in inc/functions.php

/**
 * Fetch the IP address of the current user.
 *
 * @return string The IP address.
 */
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;
}
(2019-11-13, 07:58 PM)NoRules Wrote: [ -> ]Hi,

maybe in inc/functions.php

/**
 * Fetch the IP address of the current user.
 *
 * @return string The IP address.
 */
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;
}

Thank you very much .. this can be a good starting point .. i will work on this function and see ..

it seems there is some builtin setting "if($mybb->settings['ip_forwarded_check'])" that check for the proxie ips..

(2019-11-13, 09:00 PM)info44 Wrote: [ -> ]
(2019-11-13, 07:58 PM)NoRules Wrote: [ -> ]Hi,

maybe in inc/functions.php

/**
 * Fetch the IP address of the current user.
 *
 * @return string The IP address.
 */
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;
}

Thank you very much .. this can be a good starting point .. i will work on this function and see ..

it seems there is some builtin setting "if($mybb->settings['ip_forwarded_check'])" that check for the proxie ips..


Fixed.. thank you