Bringing Location to the Internet
   

PHP Module

This module is a PHP module that enables the user to find the country, region, city, coordinates, zip code, ISP, domain name, timezone, connection speed, IDD code, area code, weather station code, weather station name, MCC, MNC, mobile brand name, elevation and usage type 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.

Download IP2Location PHP Module (1,016.42 kB) Version: 6.0.0

 

Installation
  1. Download and unzip and package.
    ip2location-php-x.xx.zip

 

Sample Codes
<?php
require_once('IP2Location.php');

// Standard lookup with no cache
$loc = new IP2Location('databases/DB24.BIN');

/*
   Cache whole database into system memory and share among other scripts & websites
   WARNING: Please make sure your system have sufficient RAM to enable this feature
*/
//$loc = new IP2Location('databases/DB24.BIN', IP2Location::SHARED_MEMORY);

/*
   Cache the database into memory to accelerate lookup speed
   WARNING: Please make sure your system have sufficient RAM to enable this feature
*/
//$loc = new IP2Location(ROOT . 'databases/DB24.BIN', IP2Location::MEMORY_CACHE);

$ip = $_SERVER['REMOTE_ADDR'];
$record = $loc->lookup($ip, IP2Location::ALL);

echo 'IP Address: ' . $record->ipAddress . '<br />';
echo 'IP Number: ' . $record->ipNumber . '<br />';
echo 'ISO Country Code: ' . $record->countryCode . '<br />';
echo 'Country Name: ' . $record->countryName . '<br />';
echo 'Region Name: ' . $record->regionName . '<br />';
echo 'City Name: ' . $record->cityName . '<br />';
echo 'Latitude: ' . $record->latitude . '<br />';
echo 'Longitude: ' . $record->longitude . '<br />';
echo 'ZIP Code: ' . $record->zipCode . '<br />';
echo 'Time Zone: ' . $record->timeZone . '<br />';
echo 'ISP Name: ' . $record->isp . '<br />';
echo 'Domain Name: ' . $record->domainName . '<br />';
echo 'Net Speed: ' . $record->netSpeed . '<br />';
echo 'IDD Code: ' . $record->iddCode . '<br />';
echo 'Area Code: ' . $record->areaCode . '<br />';
echo 'Weather Station Code: ' . $record->weatherStationCode . '<br />';
echo 'Weather Station Name: ' . $record->weatherStationName . '<br />';
echo 'MCC: ' . $record->mcc . '<br />';
echo 'MNC: ' . $record->mnc . '<br />';
echo 'Mobile Carrier Name: ' . $record->mobileCarrierName . '<br />';
echo 'Elevation: ' . $record->elevation . '<br />';
echo 'Usage Type: ' . $record->usageType . '<br />';
?>

 

Sample Database (BIN)

Evaluation version of the database file having limited range of IP address information. You can query all IP addresses from 0.0.0.0 to 99.255.255.255 only.