Web Hosting Info

Search:

featured partner

The IP to Country Database

Handbook

Web Service
Last updated by jinesh on Wed, 12/21/2005 - 07:05
NOTE: Read this first HTTP GET based Web Service is DOWN for now.

IP-to-Country provides a HTTP GET based Web Service to access country information for a particular IP Address.

The format of the request can be one of the following:
1) http://ip-to-country.directi.com/country/name/IP_ADDRESS
2) http://ip-to-country.directi.com/country/code2/IP_ADDRESS
3) http://ip-to-country.directi.com/country/code3/IP_ADDRESS
In the above URL's IP_ADDRESS has to be replaced with the IP address for which you want to retrive country information.

The first request will return the name of the country while the next two will return the 2 letter and 3 letter country code as defined in the ISO 3166 Country Codes Standard respectively.

In PHP, you can make the first request using the following code snippet:
$handle = fopen("http://ip-to-country.directi.com/country/name/".$ip, 'r');
echo fgets($handle, 4096);
fclose($handle);
The other two requests can be achieved by simply replacing "name" with either "code2" or "code3".
    Comment viewing options:
    Select your preferred way to display the comments and click 'Save settings' to submit your changes.
    Easily get IP in php
    Posted by Denzo on Fri, 07/18/2003 - 02:35.
    You get the user's IP by using $REMOTE_ADDR
    So this code will load the country name in a string called $country:
    $handle = fopen("http://ip-to-country.directi.com/country/name/".$REMOTE_ADDR, 'r');
    $country = fgets($handle, 4096);
    fclose($handle);


    ____________
    Visit xboxcovers.net
     
    HTTP_X_FORWARDED_FOR
    Posted by sandeep on Fri, 07/18/2003 - 11:03.
    If the user is behind a proxy,
    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
      ...
    }
    
    look in $_SERVER['HTTP_X_FORWARDED_FOR'] and rule out RFC 1918 IP's. That should leave you with the users real IP address.

    If not, then $_SERVER['REMOTE_ADDR'] is what you need.
    Even simpler
    Posted by nlopes on Sun, 09/07/2003 - 04:21.
    In php just do this:

    $country=file("http://ip-to-country.directi.com/country/name/".$ip);

    (>PHP 3)
     
    Re: Even Simpler
    Posted by melchiorus on Sat, 10/04/2003 - 13:29.
    In reply to nlopes post...

    This will work but it will just read the country name into an array so you'll have to add this bit:

    foreach($country as $line) {
    echo $line."\n";
    }

    It would be simpler to just read it using fread and fopen...
     
    Re: even more simpler
    Posted by Denzo on Thu, 01/01/2004 - 10:58.
    $ip = ($_SERVER['HTTP_X_FORWARDED_FOR'] == "" ? $_SERVER['REMOTE_ADDR'] : $_SERVER['HTTP_X_FORWARDED_FOR']);
    $country = file_get_contents("http://ip-to-country.directi.com/country/name/".$ip);
    
    ___________
    Visit xboxcovers.net
     
    Re: Re: even more correct about quotes and returned values
    Posted by VGR on Sun, 01/25/2004 - 03:15.
    $ip=($_SERVER['HTTP_X_FORWARDED_FOR']=="")?$_SERVER['REMOTE_ADDR']:$_SERVER['HTTP_X_FORWARDED_FOR'];
    $country=(($poub=file_get_contents("http://ip-to-country.directi.com/country/name/$ip"))<>"")?$poub:'UNKNOWN';
    

    you could also have mentionend that your solution requires PHP 4.3+ while others' do not. See the online PHP manual for the workaround of file_get_contents() for previous PHP versions.

    Regards

    VGR
    former PHP/MySql/Pascal Guru at experts-exchange.COM, now working for europeanexperts.ORG
     
    Beware
    Posted by VGR on Sun, 01/25/2004 - 03:23.
    please also be aware (thanks Jenclod) that you may very well get 'This service is currently down. ' as the country name or code ;-)
    IP@ *.*.*.* has country 'This service is currently down. '
     
    Even simpler
    Posted by Daath on Thu, 04/22/2004 - 16:09.
    Or simpler yet:

    $country = implode('', file("http://ip-to-country.directi.com/country/name/".$ip));

    -
    Any technology distinguishable from magic, is insufficiently advanced.
    Oop
    Posted by Jomas56 on Sat, 04/28/2007 - 03:52.
    Visits is important: mature black ass Mature black ass is not white. lesbian arrest Lesbian arrest is abnormal. gay boy cock There is gay boy cock. cum facial shot There is cum facial shot here. naked boob Big naked boob is very attractive. mature big breasted There are few mature big breasted in the room. lesbian dildo fucking Do you saw lesbian dildo fucking? gay brothers There are gay brothers, but not twink. naked older woman It is pretty naked older woman. mature bitch Mature bitch is love. lesbian ass fuck See lesbian ass fuck in the street? gay bukkake What is it? It is gay bukkake. teenie whore Said :" teenie whore and other sluts." teen all over Teen all over, isn't it? teens showing That teens showing them bodies. asian teen fucking Hard asian teen fucking - said Mariana. fetish shemale Few fetish shemale is not anomal. cum hand job shot Do yo want cum hand job shot? Yes, it is. big boobs chubb Big boobs chubb? What is it? anal cream pee I think, anal cream pee. fetish sucking Fetish sucking is normal. naked teen young There are naked teen young in the pool. big boobs dildo Her named: " big boobs dildo ". asian teen hardcore Asian teen hardcore is amazing. anal comics She draw anal comics everyday. fetish threesome This is fetish threesome - male + female + male. big boobs ebony There are big boobs ebony in the city. asia mature woman This is asia mature woman in the short dress. anal cum swapping Anal cum swapping, is not it? american idol naked See american idol naked only now. The great thanks.