Added geolocation script. When people register it geolocates their IP and save in table `accounts`, column 'flag' [2 letters country code]. Geolocation takes around 0.0002 second [uses 38 files with information about IPs location, all together got 4MB, it loads one file for one geolocation]. No more stupid question 'where are you from?' and list of 200 countries.
Added 'flag' (image) to highscores.php, characters.php, whoisonline.php (method that doesn't use any extra query, not like popular old version.. [400 SQL queries per 1 highscore page])
Geolocation is in class 'Website', code:
Data (IPs location) prepared by script:
Newest list of IPs location (that you must parse by script above and add to folder /cache/flags/ in acc. maker) you can get free:
MaxMind - GeoLite Databases | Free IP Geolocation Database
Get 'GeoLite Country' [not city] in '.csv' format (in .zip, unzip before you run PHP script).
Files updated!
.zip
http://ots.me/gesior/Gesior_2012_beta_0.3.6_2012_10_07.zip
file viewer
GESIOR 2012 ver. 1.0.0 BETA for 0.3.6
Added 'flag' (image) to highscores.php, characters.php, whoisonline.php (method that doesn't use any extra query, not like popular old version.. [400 SQL queries per 1 highscore page])
Geolocation is in class 'Website', code:
PHP:
public static function getCountryCode($IP)
{
$a = explode(".",$IP);
if($a[0] == 10) // IPs 10.0.0.0 - 10.255.255.255 = private network, so can't geolocate
return '';
if($a[0] == 127) // IPs 127.0.0.0 - 127.255.255.255 = local network, so can't geolocate
return '';
if($a[0] == 172 && ($a[1] >= 16 && $a[1] <= 31)) // IPs 172.16.0.0 - 172.31.255.255 = private network, so can't geolocate
return '';
if($a[0] == 192 && $a[1] == 168) // IPs 192.168.0.0 - 192.168.255.255 = private network, so can't geolocate
return '';
if($a[0] >= 224) // IPs over 224.0.0.0 are not assigned, so can't geolocate
return '';
$longIP = $a[0] * 256 * 256 * 256 + $a[1] * 256 * 256 + $a[2] * 256 + $a[3]; // we need unsigned value
$countries = unserialize(file_get_contents('cache/flags/flag' . bcdiv($longIP, 100000000, 0))); // load file
$lastCountryCode = '';
foreach($countries as $fromLong => $countryCode)
{
if($fromLong > $longIP)
break;
$lastCountryCode = $countryCode;
}
return $lastCountryCode;
}
PHP:
$lines = file('GeoIPCountryWhois.csv');
$lastIP = 0;
$lastCountry = '';
$fileC = -1;
$data = array();
foreach ($lines as $line_num => $line)
{
$info = explode(",", $line, 6);
$iIP = trim($info[2], '"');
$iC = trim($info[4], '"');
if(bcdiv($iIP, 100000000, 0) != $fileC)
{
$fileC = bcdiv($iIP, 100000000, 0);
$data[$fileC][$lastIP] = $lastCountry;
}
$data[$fileC][$iIP] = strtolower($iC);
$lastIP = $iIP;
$lastCountry = strtolower($iC);
}
foreach($data as $i => $dat)
{
file_put_contents('flags/flag' . $i, serialize($dat));
}
MaxMind - GeoLite Databases | Free IP Geolocation Database
Get 'GeoLite Country' [not city] in '.csv' format (in .zip, unzip before you run PHP script).
Files updated!
.zip
http://ots.me/gesior/Gesior_2012_beta_0.3.6_2012_10_07.zip
file viewer
GESIOR 2012 ver. 1.0.0 BETA for 0.3.6