Location: PHPKode > projects > Statiqz, website statistics > statiqz/ctrl/UpdateCtrl.class.php
<?php
    require_once 'ctrl/BaseCtrl.class.php';

    require_once 'xdbx/CountriesXdbx.class.php';
    require_once 'xdbx/UsersXdbx.class.php';
    require_once 'xdbx/VisitorsXdbx.class.php';
    require_once 'xdbx/IpcountryXdbx.class.php';
    require_once 'xdbx/VisitsXdbx.class.php';
    require_once 'xdbx/OsXdbx.class.php';
    require_once 'xdbx/BrowsersXdbx.class.php';
    require_once 'xdbx/ReferrersXdbx.class.php';

    class UpdateCtrl extends BaseCtrl {
        function UpdateCtrl() {

        }

        function process() {
            if (isset($_GET['ID'])) {
                $ID     = $_GET['ID'];
                $xres   = $_GET['xres'];
                $yres   = $_GET['yres'];
                $bits   = $_GET['bits'];
                $java   = $_GET['java'];
                $js     = $_GET['js'];
                $refr   = $_GET['refr'];
                $agnt   = $_SERVER['HTTP_USER_AGENT'];
                $ip     = $_SERVER['REMOTE_ADDR'];

                $usersXdbx      = new UsersXdbx();
                $ipcountryXdbx  = new IpcountryXdbx();
                $visitorsXdbx   = new VisitorsXdbx();
                $visitsXdbx     = new VisitsXdbx();
                $osXdbx         = new OsXdbx();
                $browsersXdbx   = new BrowsersXdbx();
                $countriesXdbx  = new CountriesXdbx();
                $referrersXdbx  = new ReferrersXdbx();

                // proceed only when a valid userID has been given
                if ($user = $usersXdbx->getUserByID($ID)) {
                    $originReferrer = parse_url($_SERVER['HTTP_REFERER']);

                    // proceed only when the account if active and if the originating referrer matches the user url
                    if (($user[0]['active'] == 1) && ($user[0]['url'] == substr($_SERVER['HTTP_REFERER'],0, strlen($user[0]['url'])))) {

                        // if this is the first statsupdate then update or add visitordata
                        if (!isset($_SESSION['visitorID'])) {

                            // if visitor already exists then update data else add visitordata
                            if ($visitor = $visitorsXdbx->getVisitorByIp($ip)) {
                                // modify visitor information of an existing visitor
                                $visitorID = $visitor[0]['ID'];

                                if ($country = $ipcountryXdbx->getCountry($ip)) {
                                    $location   = $countriesXdbx->getCountryByCode($country[0]['code2']);
                                    $countryID = $location[0]['ID'];
                                } else {
                                    $countryID = 1;
                                }

                                $browserID  = $browsersXdbx->getBrowserByUserAgent($agnt);
                                $osID       = $osXdbx->getOsByUserAgent($agnt);

                                $visitorsXdbx->modifyVisitor($countryID, $xres, $yres, $bits, $java, $js, $browserID, $osID, $agnt, $visitorID); 
                            } else {
                                // add visitor information of a new visitor
                                if ($country = $ipcountryXdbx->getCountry($ip)) {
                                    $location   = $countriesXdbx->getCountryByCode($country[0]['code2']);
                                    $countryID  = $location[0]['ID'];
                                } else {
                                    $countryID = 1;
                                }

                                $browserID  = $browsersXdbx->getBrowserByUserAgent($agnt);
                                $osID       = $osXdbx->getOsByUserAgent($agnt);

                                $visitorID = $visitorsXdbx->addVisitor($countryID, $ip, $xres, $yres, $bits, $java, $js, $browserID, $osID, $agnt);
                            }

                            // set session value that prevents the above statements from execution
                            $_SESSION['visitorID'] = $visitorID;
                        } else {
                            $visitorID = $_SESSION['visitorID'];
                        }

                        // store visit information
                        $referrer = parse_url(strip_tags($refr));

                        if ($refrID = $referrersXdbx->getIDByReferrer($referrer['host'])) {
                            $referrerID = $refrID[0]['ID'];
                        } else {
                            $referrerID = $referrersXdbx->addReferrer($referrer['host']);
                        }

                        $visitsXdbx->addVisit($ID, $visitorID, $referrerID);

                        // read the graphical data from spacer.gif into $header
        				$fp     = fopen('gfx/spacer.gif', 'r');
        				$header = fread($fp, filesize('gfx/spacer.gif'));

        				fclose($fp);

                        // send the appropriate HTTP header
        				header('Content-type: image/gif');

        				return $header;
                    }
                }
            }

            return false;
        }
    }
?>
Return current item: Statiqz, website statistics