Login   Register  
PHP Classes
elePHPant
Icontem

File: sample.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Chris  >  IP2Location PHP Module  >  sample.php  >  Download  
File: sample.php
Role: Example script
Content type: text/plain
Description: sample code
Class: IP2Location PHP Module
Get geographical details of an IP with IP2Location
Author: By
Last change: Fixed the required_once filename to ip2location.class.php
Updated the database path pointing to the same folder of sample file.
Date: 8 months ago
Size: 1,126 bytes
 

Contents

Class file image Download
<?php
// Preset PHP settings
error_reporting(E_ALL);
ini_set('display_errors'1);
set_time_limit(0);

require_once(
'ip2location.class.php');

// Standard lookup with no cache
$loc = new IP2Location('IP-COUNTRY-SAMPLE.BIN'IP2Location::FILE_IO);

/*
   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/IP-COUNTRY-SAMPLE.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/IP-COUNTRY-SAMPLE.BIN', IP2Location::MEMORY_CACHE);

$ip '8.8.8.8';

// Lookup for single field
echo 'Country Code: ' $loc->lookup($ipIP2Location::COUNTRY_CODE) . '<br />';
echo 
'Country Name: ' $loc->lookup($ipIP2Location::COUNTRY_NAME) . '<br />';

// Lookup for all fields
$record $loc->lookup($ipIP2Location::ALL);

echo 
'<pre>';
print_r($record);
echo 
'</pre>';
?>