hello everybody,
I’m working on application which uses the IP address of the device to identify location information such as city, state, country. The script works but its picking up the IP address that’s assigned by the router.
how can I get the actually ip address that I need to use in my script to get the correct location information?
Current setup I have is the internet cable box which is connected to a wireless router and my laptop receives the IP address from the wireless router as such 192.168.0.94.
I use an external site for retrieve the location information => http://www.geoplugin.net
And the script I use in my application to get the IP address.
function get_ip_address()
{ $aa = array
( 'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR'
);
foreach ( $aa as $key)
{ if(array_key_exists($key, $_SERVER) === true)
{ foreach (explode(',', $_SERVER[$key]) as $ip)
{ if (filter_var($ip, FILTER_VALIDATE_IP) !== false)
{ return $ip; }
}
}
}
}