Passing the IP then returning the country

Discussion in 'PHP' started by junedc, Jan 9, 2013.

  1. #1
    Hi DP members and php master,

    Is there any free or paid web services that can be used for geo location checking.
    i want to pass the IP of the current visitor/user to a webservice/site then this will return give me the visitors country.
     
    junedc, Jan 9, 2013 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    http://pecl.php.net/geoip

    You will need maxmind GeoIP installed.

    There is a free database/service.

    On a lot of systems, this will get you going:

    Where {pkgmanager} is yum, or apt-get
    {pkgmanager} install GeoIP
    Code (markup):
    pecl install geoip
    Code (markup):
    echo "extension=geoip.so" > /etc/php.d/geoip.ini
    Code (markup):
    If you use php-fpm then

    service php-fpm restart
    Code (markup):
    If you use nginx or apache, then execute

    Where {httpd} is httpd, or nginx
    service {httpd} restart
    Code (markup):
    You will need to add a cron job for monthly updates to the GeoIP.dat
     
    krakjoe, Jan 9, 2013 IP
  3. junedc

    junedc Active Member

    Messages:
    175
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Thanks Krakjoe for the prompt response. But i'm using a shared hosting, will they allow me to install it?
     
    junedc, Jan 9, 2013 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    krakjoe, Jan 9, 2013 IP
  5. junedc

    junedc Active Member

    Messages:
    175
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    Thanks krakjoe, anybody else having different implementation ?
     
    junedc, Jan 9, 2013 IP
  6. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #6
    ThePHPMaster, Jan 9, 2013 IP
  7. junedc

    junedc Active Member

    Messages:
    175
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #7
    Thanks ThePHPMaster saw the link you gave me :)
     
    junedc, Jan 10, 2013 IP
  8. edduvs

    edduvs Well-Known Member

    Messages:
    394
    Likes Received:
    31
    Best Answers:
    3
    Trophy Points:
    160
    #8
    You can still use an API which is relatively fast if you can't afford to install the standalone db from maxmind. (http://freegeoip.net/{FORMAT}/{IP_OR_HOSTNAME})

    Example : http://freegeoip.net/json/79.112.239.66 (csv, xml is available too)

    JSON callbacks are supported by adding the callbackargument to the query string: http://freegeoip.net/json/79.112.239.66?callback=show which results into:
    
    
    show({"city": "Vaslui", "region_code": "38", "region_name": "Vaslui", "metrocode": "", "zipcode": "", "longitude": "27.7333", "latitude": "46.6333", "country_code": "RO", "ip": "79.112.239.66", "country_name": "Romania"});
    Code (markup):
     
    edduvs, Jan 13, 2013 IP