Tuesday, March 3

Geographical location of the IP address using PHP

This code uses the PHP Webservice of http://www.geoplugin.com/ to geolocate IP addresses

Geographical location of the IP address (visitor) and locate currency (symbol, code and exchange rate) are returned.

See http://www.geoplugin.com/webservices/php for more specific details of this free service

<?PHP
    class Geocall{
       
        public function get_location()
        {
            require_once('geoplugin.class.php');
       
            $geoplugin = new geoPlugin();
                   
            //locate the IP
         
            $geoplugin->locate();
            $data['json'] = array("ip"=>"{$geoplugin->ip}",
                          "city" => "{$geoplugin->city}",
                          "countryNmae" => "{$geoplugin->countryName}",
                "currency" => "{$geoplugin->currency}",
                "countryCode" => "{$geoplugin->countryCode}",
        );
           
            echo json_encode($data);
        }
    }
   
    $geo_call = new Geocall();
    $data=$geo_call->get_location();
   
    //prints location
    print_r($data);
?>


There are so many options available at http://www.geoplugin.com/webservices/php

No comments:

Post a Comment