2
require_once("DBManager.class.php");
4
function get_location($ip) {
5
$content = @file_get_contents('http://api.hostip.info/?ip='.$ip);
6
if ($content != FALSE) {
7
$xml = new SimpleXmlElement($content);
8
$coordinates = $xml->children('gml', TRUE)->featureMember->children('', TRUE)->Hostip->ipLocation->children('gml', TRUE)->pointProperty->Point->coordinates;
9
$longlat = explode(',', $coordinates);
10
$location['longitude'] = $longlat[0];
11
$location['latitude'] = $longlat[1];
12
$location['citystate'] = '==>'.$xml->children('gml', TRUE)->featureMember->children('', TRUE)->Hostip->children('gml', TRUE)->name;
13
$location['country'] = '==>'.$xml->children('gml', TRUE)->featureMember->children('', TRUE)->Hostip->countryName;
19
$dbManager = new DBManager();
22
if (array_key_exists('prodID', $_REQUEST))
23
$prodID = mysql_real_escape_string($_REQUEST['prodID']); // prevent SQL injection
28
if (array_key_exists('version', $_REQUEST))
29
$ver = mysql_real_escape_string($_REQUEST['version']); // prevent SQL injection
34
$ip = $_SERVER['REMOTE_ADDR'];
37
$location = get_location($ip);
39
$country = (($location != false)?($location['country']):('Unknown'));
40
$long = $location['longitude'];
41
$lat = $location['latitude'];
43
// If ip is private -> die
44
if ($country == '(Private Address)')
47
// If product ID doesnt exist -> die
48
$dbManager->executeQuery("SELECT * FROM stats_products WHERE prodID = '$prodID'");
49
if ($dbManager->getSelectedRows() == 0)
52
// Add country to list (if not already listed)
53
$dbManager->executeQuery("INSERT INTO stats_countries (country) VALUES('$country')");
55
// Add version to list (if not already listed)
56
$dbManager->executeQuery("INSERT INTO stats_versions (prodID, version) VALUES('$prodID', '$version')");
59
$dbManager->executeQuery("INSERT INTO stats_log (datetime, version, country, ip, longitude, latitude) VALUES (NOW(), '$ver', '$country', '$ip', '$long', '$lat')");
b'\\ No newline at end of file'