PHP Script To Detect And Display Visitor’s Country Using His IP Address Location Lookup

Share:

PHP Script To Detect And Display Visitor’s Country Using His IP Address Location Lookup. Have you ever been asked, how do I detect the visitor’s country of a website ? And How to display visitor’s country into our website ?
PHP Script To Detect And Display Visitor’s Country Using His IP Address Location LookupFor those of you who would like to get an answer to this question for free, please read more in this post because we discussed it in detail on how to detect and display visitor’s country of website visitors through an analysis of their IP address because every country has a unique IP Address location different from one another location so country from each visitor can be very easy to identify.

PHP Script To Detect And Display Visitor’s Country Using His IP Address Location Lookup

Immediately, the following tutorial to detect and display the visitor’s country using their IP Address location lookup :
Script that we use to detect and identify the state of each visitor on our website is a php script so that when the visitor’s browser disable their javascript, this script can still walk. The php script is :
dispay-visitor-country-using-ip-address.php

<?php
echo "<a href="http://tutorial.world.edu/web-development/php-script-detect-display-visitors-country-ip-address-location-lookup/">Detect And Display Visitor’s Country Using IP Address Location Lookup</a> | <a href="http://tutorial.world.edu">Tutorial.World.Edu</a>";
$IPaddress=$_SERVER['REMOTE_ADDR'];
$two_letter_country_code=iptocountry($IPaddress);
include("ip_files/countries.php");
$country_name=$countries[$two_letter_country_code][1];
print "Country name: $country_name<br>";

function iptocountry($ip) {
    $numbers = preg_split( "/\./", $ip);
    include("ip_files/".$numbers[0].".php");
    $code=($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]);
    foreach($ranges as $key => $value){
        if($key<=$code){
            if($ranges[$key][0]>=$code){$two_letter_country_code=$ranges[$key][1];break;}
            }
    }
    if ($two_letter_country_code==""){$two_letter_country_code="unkown";}
    return $two_letter_country_code;
}
?>

In order for this script to run smoothly and can detect a country based on IP Address Location of website visitors. You should install the file that contains the IP Code every country in a special folder for example: ip_files. The workings of the PHP script above is to detect visitor IP address, then the IP address from visitors will be matched with the existing IP Address code in the ip_files file to identify the location and state visitors. Here’s a link to get the ip_files, download now

For those of you who do not want trouble in learning the programming languages ​​such as above, you can take the easy road by installing widgets and plugins directly into your blog platform. This widget can be installed into the blog platform blogger, wordpress or other. The download

Thanks for reading PHP Script To Detect And Display Visitor’s Country Using His IP Address Location Lookup

[Tutorial.World.Edu]

3 thoughts on “PHP Script To Detect And Display Visitor’s Country Using His IP Address Location Lookup

  1. Hi,
    In the first thanks for this tutorial.
    & now i wanna get the report from all of the visitors (e.x: malaysia:30, singapore:80 …).
    how can i do that?

Leave a Reply

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