Get the continent/country or location of user in php?

Is possible to get the continent from where the user it is accessing a site?
I do know i can get the language of the browser like this:::

<?php
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
switch ($lang){
    case "fr":
        //echo "PAGE FR";
        include("index_fr.php");//include check session FR
        break;
    case "it":
        //echo "PAGE IT";
        include("index_it.php");
        break;
    case "en":
        //echo "PAGE EN";
        include("index_en.php");
        break;        
    default:
        //echo "PAGE EN - Setting Default";
        include("index_en.php");//include EN in all other cases of different lang detection
        break;
}
?>

REF

Read More

Also i do know there is something php function call -> geoip_continent_code_by_name
which if a pass a string with the host name it will return me:

Code Continent name

AF  Africa
AN  Antarctica
AS  Asia
EU  Europe
NA  North america
OC  Oceania
SA  South america

But this only returns me the host name, so is there any way to get the same result but for the user who is accessing the site? or is even possible to do?

Related posts

Leave a Reply

2 comments

  1. I recommend using the Maxmind GeoLite2 database starting out. It is has a creative commons license, and you can upgrade to the commercial GeoIP2 database at a later time if you need more complete IP coverage. The country and continent codes are available in this database.

    I describe how to compile the extension, and how to use the mmdb databases in PHP here:

    Intro to Maxmind GeoLite2 with Kohana PHP

    enter image description here