~lss-team/lilsoftstats/trunk

« back to all changes in this revision

Viewing changes to update.php

  • Committer: Nick
  • Date: 2011-11-14 04:10:28 UTC
  • Revision ID: nick@little-apps.org-20111114041028-cvmpwq6z6hx3pkya
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
        require_once("DBManager.class.php");
 
3
        
 
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;
 
14
                        return $location;
 
15
                }
 
16
                else return false;
 
17
        }
 
18
        
 
19
        $dbManager = new DBManager();
 
20
        
 
21
        // Get product id
 
22
        if (array_key_exists('prodID', $_REQUEST))
 
23
                $prodID = mysql_real_escape_string($_REQUEST['prodID']); // prevent SQL injection
 
24
        else 
 
25
                $prodID = "Unknown";
 
26
        
 
27
        // Get version
 
28
        if (array_key_exists('version', $_REQUEST))
 
29
                $ver = mysql_real_escape_string($_REQUEST['version']); // prevent SQL injection
 
30
        else 
 
31
                $ver = "Unknown";
 
32
 
 
33
        // Get the ip address
 
34
        $ip = $_SERVER['REMOTE_ADDR'];
 
35
 
 
36
        // Get tbe country
 
37
        $location = get_location($ip);
 
38
        
 
39
        $country = (($location != false)?($location['country']):('Unknown'));
 
40
        $long = $location['longitude'];
 
41
        $lat = $location['latitude'];
 
42
        
 
43
        // If ip is private -> die
 
44
        if ($country == '(Private Address)')
 
45
                die();
 
46
                
 
47
        // If product ID doesnt exist -> die
 
48
        $dbManager->executeQuery("SELECT * FROM stats_products WHERE prodID = '$prodID'");
 
49
        if ($dbManager->getSelectedRows() == 0)
 
50
                die();
 
51
                
 
52
        // Add country to list (if not already listed)
 
53
        $dbManager->executeQuery("INSERT INTO stats_countries (country) VALUES('$country')");
 
54
                
 
55
        // Add version to list (if not already listed)
 
56
        $dbManager->executeQuery("INSERT INTO stats_versions (prodID, version) VALUES('$prodID', '$version')");
 
57
                
 
58
        // Update table
 
59
        $dbManager->executeQuery("INSERT INTO stats_log (datetime, version, country, ip, longitude, latitude) VALUES (NOW(), '$ver', '$country', '$ip', '$long', '$lat')");
 
60
?>
 
 
b'\\ No newline at end of file'