PHP Classes

IP2Location Lite Web Viewer: Query IP2Location data to display using AJAX

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 78%Total: 440 This week: 1All time: 6,247 This week: 560Up
Version License PHP version Categories
ip2locationwebviewer 1.0.0GNU Lesser Genera...5Networking, PHP 5, Geography, AJAX
Description 

Author

This package can query IP2Location data to display using AJAX.

It performs queries to a IP2Location Lite version database file to retrieve information.

The retrieved data is served in JSON format for AJAX requests to be displayed.

Picture of Chi H.
  Performance   Level  
Name: Chi H. <contact>
Classes: 28 packages by
Country: France France
Age: 39
All time rank: 34222 in France France
Week rank: 106 Up5 in France France Up
Innovation award
Innovation award
Nominee: 22x

Winner: 3x

Example

<?php
require_once 'IP2LocationCalc.php';
                    
error_reporting(E_ERROR | E_PARSE);
//ini_set("display_errors",0);
//ini_set('error_reporting',0);
//set_time_limit(60*2);
ini_set('max_execution_time', 300);

$ip_data=[];

//Load file using FILE_IO method
$db = new \IP2Location\Database('./databases/IP2LOCATION-LITE-DB11.BIN', \IP2Location\Database::FILE_IO);
switch (
$_GET["dir"]) {
    case
"down" ; {
      
$from=$_GET["from"];
      
$to=$_GET["to"];
      
$step=$_GET["step"];
      
$cc=$_GET["cc"];
    }
    break;
    default : {
       
$from=$_GET["to"];
       
$to=$_GET["from"];
       
$step=$_GET["step"];
       
$cc=$_GET["cc"];
       
$step*=-1;
    }
    break;
}
if (
$from<0 && $to<0) {
   
$from=0;
   
$to=from+$step*$step;
}
//$from=-2721030656;$to=-1060086267;$step=16777216;$dir=down;$cc=All;
//$from=-5721030656;$to=-4060086267;$step=16777216;$dir=down;$cc=CN;
//from=-1720253316&to=-42531716&step=16777216&dir=up&cc=All;
//$from=85196800;$to=91684864;$step=65536;$cc="VN";
//$from=0;$to=6488064;$step=65536;$cc="JP";
//$s=ip2long("0.0.0.0");
$e=sprintf('%u', ip2long("255.255.255.255"));

if (
$cc != "All") {
    foreach (
range(0,$e,256*256*256) as $long) {
       
$records = $db->lookup(long2ip($long), \IP2Location\Database::ALL);
        if (
$records["countryCode"]!=$cc) {
           
$b=sprintf('%u', long2ip($long));
           
$a=explode(".",$b)[0];
           
$step4[$a]= [$a,$long,$records["countryCode"]];
        }
    }
    while (
$from<$to && $from>=0 || count($ip_data)<99) {
        if (
count($ip_data)>99) break;
       
$b=sprintf('%u', long2ip($from));
       
$a = explode(".",$b)[0];
        if (!
$step4[$a] && $a<129) {
           
$records = $db->lookup(long2ip($from), \IP2Location\Database::ALL);
            if (
$cc==$records['countryCode'] || $cc=="All") {
               
$ip_data[] = ['ipaddr'=>$records['ipAddress'],
                              
'countryCode'=>$records['countryCode'],
                              
'regionName'=>$records['regionName'],
                              
'cityName'=>$records['cityName'],
                              
'lat'=>$records['latitude'],
                              
'long'=>$records['longitude'],
                              
'zipCode'=>$records['zipCode'],
                              
'timeZone'=>$records['timeZone'],
                              
'from'=>$from,
                              
'to'=>$to
                              
];
            }
        } else if (
$a>129){
            break;
        }
       
$from+=$step;
    }

} else {
   
    while (
$from<$to && $from>=0 || count($ip_data)<99) {
        if (
count($ip_data)>99) break;
        if (
$from>=$e) break;
       
       
$records = $db->lookup(long2ip($from), \IP2Location\Database::ALL);
       
$ip_data[] = ['ipaddr'=>$records['ipAddress'],
                      
'countryCode'=>$records['countryCode'],
                      
'regionName'=>$records['regionName'],
                      
'cityName'=>$records['cityName'],
                      
'lat'=>$records['latitude'],
                      
'long'=>$records['longitude'],
                      
'zipCode'=>$records['zipCode'],
                      
'timeZone'=>$records['timeZone'],
                      
'from'=>$from,
                      
'to'=>$to
                      
];
       
$from+=$step;
    }
}

       
header("Expires: Sat, 1 Jan 2005 00:00:00 GMT");
header("Last-Modified: ".gmdate( "D, d M Y H:i:s")."GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
echo
json_encode($ip_data,true);












Details

IP2Location Lite web viewer 1. What is does it do? IP2Location Lite web viewer is a simple viewer for the free IP2Location Lite database making use of JS, PHP, Ajax, Json, HTML, CSS. 1.2. Features - Supports the free IP2location Lite database (DB15 binary file) with millions of updated IP addresses. - Supports sorting of the view with 2 different orders (up and down) and to reset it. - Supports infinite scroll. Navigate millions of IP addresses with the right scrollbar. - Supports a filter with 4 different subnet masks (255.255.255.255, 255.255.255.0, 255.255.0.0,255.0.0.0). - Supports a filter with a country code (beta). - Supports searching for an ip address. - Supports a sticky navigation bar. - Asynchronous database query with JS. - faster search with the free optimized IP2Location php library (winner of the IP2Location php library optimization contest 2016). 2. Requirements -Webserver with PHP5+ 3. Installation Download the beta. Unpack the archive and copy it to your webserver. 4. Tutorial 4.1 The source code 4.1.1 Download the source code and copy it to your webserver. 4.2 Free IP2Location lite 4.2.1 It requires the free IP2Location lite database (binary file) in the database folder in the application folder. Create an folder "database" inside the application folder and copy the free IP2Location Lite database (binary file) to it. 4.3 PHP5 4.4.1 It requires the free PHP5+ for webserver. 5. Changelog 14.08.2016 Initial release

Screenshots  
  • Screenshot
  Files folder image Files  
File Role Description
Accessible without login Plain text file ajax.php Example class file
Accessible without login Plain text file example.js Data example file
Plain text file IP2locationCalc.php Class class file
Accessible without login Plain text file main.css Data css stylesheet
Accessible without login Plain text file main.html Data HTML page
Accessible without login Plain text file main.js Data class source
Accessible without login Plain text file readme.md Doc. readme

 Version Control Unique User Downloads Download Rankings  
 0%
Total:440
This week:1
All time:6,247
This week:560Up
 User Ratings  
 
 All time
Utility:100%StarStarStarStarStarStar
Consistency:95%StarStarStarStarStar
Documentation:95%StarStarStarStarStar
Examples:90%StarStarStarStarStar
Tests:-
Videos:-
Overall:78%StarStarStarStar
Rank:46