|
Posted by thinkdj on July 14, 2008, 10:50 am
Please log in for more thread options > i am using $ip=3D $_SERVER['REMOTE_ADDR'] to retrieve the ip address of
> the client for example if the value returned from $ip is
> 50.160.190.150
To get the 3rd Octet, you may the string as the previous
posters have said...
But if you have to get the Country Information, you'll have to get if
from a database.. Entire DBs like IP2Location etc. can be purchased..
(commecial, very accurate results)
Also, Try HostIP to get country informtion. They have a good API..
[FREE]
First, get the IP using $ip=3D $_SERVER['REMOTE_ADDR'];
Get the country and city name with
http://api.hostip.info/get_html.php?ip=3D$_SERVER['REMOTE_ADDR']
Try an example http://api.hostip.info/get_html.php?ip=3D222.88.238.16 -
This will show and example of the output format. Get the text contents
using $data =3D @file_get_contents($_GET['url']); or something and
extract the info from there//
Try that .. Hope it helps...
Cheers !
Dj
>
> i would like to find out which country the request has come from. i
> believe by using the third set of numbers (in this case=3D190) from an
> ip address we can find out the country name. i can declare a variable
> with a list of country names and the range of values, what i need help
> is to extract the 3rd set of numbers from $ip.
>
> as ip address keep changing the 3rd set of numbers can be single,
> double or 3 digit number how can we extract the number that is stored
> in $ip after the second dot and before the third dot
>
> please advice.
>
> thanks.
> i am using $ip=3D $_SERVER['REMOTE_ADDR'] to retrieve the ip address of
> the client for example if the value returned from $ip is
> 50.160.190.150
>
> i would like to find out which country the request has come from. i
> believe by using the third set of numbers (in this case=3D190) from an
> ip address we can find out the country name. i can declare a variable
> with a list of country names and the range of values, what i need help
> is to extract the 3rd set of numbers from $ip.
>
> as ip address keep changing the 3rd set of numbers can be single,
> double or 3 digit number how can we extract the number that is stored
> in $ip after the second dot and before the third dot
>
> please advice.
>
> thanks.
|