DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

IP2Location PHP Module

01.21.2010
| 5127 views |
  • submit to reddit
        IP2Location PHP Module allows easy integration between your program written in PHP and the IP2Location Binary (.BIN) data file to lookup the Country, Region, City, Latitude, Longitude, ZIP code, ISP, Domain name, Time zone, Connection speed, IDD code, Area code, Weather station code and Weather station name of the location that any IP address or host name originates from. It has been optimized for speed and memory utilization. Developers can use the API to query all IP2Locationâ„¢ binary databases for applications supporting PHP. Get more geolocation information at http://www.ip2location.com and download the source code at http://www.ip2location.com/php.aspx.

<?php

include("IP2Location.inc.php");

$ip = IP2Location_open("samples/IP-COUNTRY-SAMPLE.BIN", IP2LOCATION_STANDARD);

$record = IP2Location_get_all($ip, "35.1.1.1");

echo "$record->country_short : " . $record->country_short;
echo "$record->country_long : " . $record->country_long;
echo "$record->region : " . $record->region;
echo "$record->city : " . $record->city;
echo "$record->isp : " . $record->isp;
echo "$record->latitude : " . $record->latitude;
echo "$record->longitude : " . $record->longitude;
echo "$record->domain : " . $record->domain;
echo "$record->zipcode : " . $record->zipcode;
echo "$record->timezone : " . $record->timezone;
echo "$record->netspeed : " . $record->netspeed;
echo "$record->idd_code : " . $record->idd_code;
echo "$record->area_code : " . $record->area_code;
echo "$record->weather_code : " . $record->weather_code;
echo "$record->weather_name : " . $record->weather_name;
echo "$record->ipaddr : " . $record->ipaddr;
echo "$record->ipno : " . $record->ipno;

IP2Location_close($ip);

?>