PHP IP to country lookup script.

I have already posted a script to find out the visitor’s ip. This one is similar to that one but has some additional functionality. This script uses the free IP Lookup API(Application Program Interface) provided by hostip . The script fetches the visitor’s IP from $_SERVER['REMOTE_ADDR'] and then passes on the ip to the HostIP.info API. Finally, the script processes the data returned by HostIp’s API.

Demo: IP Lookup – MyCoding.net

The following two tabs change content below.

2 thoughts on “PHP IP to country lookup script.

  1. Checkout my ip to country script as querying an external service WILL become a bottleneck in performance. External services should be queried only in background tasks (cronjobs) where visitors do not want, assume, expect your site to load quickly.

    When you actually and visually interact with the visitor, you can’t afford performance penalties. While your script might work… it’s not recommended in sites that need to stay snappy.

    • I totally agree with you. However, i made that script to keep things simple using a free api and not going into the actual process of finding the country to which the IP belongs.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">