• Get Country Name From IP Address In PHP

    Steps:

    1. Download PHP GeoIPLocation Library from the link above.

    2. Extract geoiploc.php to any folder on your server that is accessible by a web browser.

    3. Include the “geoiploc.php file and call getCountryFromIP() function with any IP address.

    4. View the sample code below for more details.

    Download PHP GeoIPLocation Library

    Download this: PHP GeoIPLocation Library – 230kb (automatically updated daily)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    
    <!--?php 
     
      include("geoiploc.php"); // Must include this
     
      // ip must be of the form "192.168.1.100"
     
      // you may load this from a database
     
      $ip = $_SERVER["REMOTE_ADDR"];
     
      echo "Your IP Address is: " . $ip . "<br ?-->";
     
      echo "Your Country is: ";
     
      // returns country code by default
     
      echo getCountryFromIP($ip);
     
      echo "
    \n";
     
      // optionally, you can specify the return type
     
      // type can be "code" (default), "abbr", "name"
     
      echo "Your Country Code is: ";
     
      echo getCountryFromIP($ip, "code");
     
      echo "
    \n";
     
      // print country abbreviation - case insensitive
     
      echo "Your Country Abbreviation is: ";
     
      echo getCountryFromIP($ip, "AbBr");
     
      echo "
    \n";
     
      // full name of country - spaces are trimmed
     
      echo "Your Country Name is: ";
     
      echo getCountryFromIP($ip, " NamE ");
     
      echo "
    \n";
     
    ?&gt;
    Tags:

Comments on this post

Leave a Reply

  • Security Code :


    six + = 15