function __construct() { $ss = new SimpleStats(); if (!$ss->is_installed() || !$ss->options['stats_enabled'] || isset($_COOKIE['simple_stats']) && $_COOKIE['simple_stats'] == $ss->hash($ss->options['username'] . $ss->options['password'])) { return; } $data = array(); $data['remote_ip'] = substr($this->determine_remote_ip(), 0, 39); // check whether to ignore this hit if (in_array($data['remote_ip'], $ss->options['ignored_ips'])) { return; } $data['resource'] = substr($ss->utf8_encode($this->determine_resource()), 0, 255); $ua = new SimpleStatsUA(); $browser = $ua->parse_user_agent($_SERVER['HTTP_USER_AGENT']); $data['platform'] = $browser['platform']; $data['browser'] = $browser['browser']; $data['version'] = substr($this->parse_version($browser['version']), 0, 15); // check whether to ignore this hit if ($data['browser'] == 1 && $ss->options['log_bots'] == false) { return; } // use DateTime instead of messing with the default timezone which could affect the calling application $tz = new DateTimeZone($ss->options['tz']); $datetime = new DateTime('now', $tz); $date = $data['date'] = $datetime->format('Y-m-d'); $time = $datetime->format('H:i:s'); // attempt to update table $table = $ss->tables['visits']; if ($ss->options['log_user_agents']) { $data['user_agent'] = $ss->esc(substr($_SERVER['HTTP_USER_AGENT'], 0, 255)); } $resource = $ss->esc($time . ' ' . $data['resource']); $ip = $ss->esc($data['remote_ip']); $query = "UPDATE `{$table}` SET hits = hits + 1, resource = CONCAT( resource, '{$resource}', '\\n' ), `end_time` = '{$time}' WHERE `date` = '{$date}' AND remote_ip = '{$ip}'"; if ($ss->options['log_user_agents']) { $query .= " AND user_agent = '{$data['user_agent']}'"; } else { foreach (array('browser', 'version', 'platform') as $key) { $v = $ss->esc($data[$key]); $query .= " AND {$key} = '{$v}'"; } } $query .= " AND TIMEDIFF( '{$time}', start_time ) < '00:30:00' LIMIT 1"; $rows = $ss->query($query); if ($rows == 0) { // this information is only needed for new visitors $data['country'] = $this->determine_country($data['remote_ip']); // always 2 chars, no need to truncate $data['language'] = substr($this->determine_language(), 0, 255); $data['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $url = parse_url($data['referrer']); $data['referrer'] = substr($ss->utf8_encode($data['referrer']), 0, 511); $data['domain'] = isset($url['host']) ? substr(preg_replace('/^www\\./', '', $url['host']), 0, 255) : ''; $data['search_terms'] = substr($ss->utf8_encode($this->determine_search_terms($url)), 0, 255); // this isn't actually used at present, but storing local timestamps without a GMT reference is asking for trouble $data['offset'] = $datetime->getOffset() / 60; // store in minutes $query = "INSERT INTO `{$table}` ( "; foreach (array_keys($data) as $key) { if ($key == 'resource') { continue; } $query .= "{$key}, "; } $query .= 'hits, resource, start_time, end_time ) VALUES ( '; foreach ($data as $key => $value) { $value = $ss->esc($value); if ($key == 'resource') { continue; } $query .= "'{$value}', "; } $query .= "'1', CONCAT( '{$resource}', '\\n' ), '{$time}', '{$time}' )"; $ss->query($query); } $ss->close(); }
foreach (array_keys($_COOKIE) as $key) { $_COOKIE[$key] = stripslashes($_COOKIE[$key]); } $_REQUEST = array_merge($_GET, $_POST); } define('SIMPLE_STATS_PATH', realpath(dirname(__FILE__))); if (file_exists(SIMPLE_STATS_PATH . '/config.php')) { require_once SIMPLE_STATS_PATH . '/config.php'; } require_once SIMPLE_STATS_PATH . '/includes/classes.php'; require_once SIMPLE_STATS_PATH . '/includes/ua.php'; require_once SIMPLE_STATS_PATH . '/includes/functions.php'; include_once SIMPLE_STATS_PATH . '/includes/countries.php'; $page = isset($_GET['p']) && in_array($_GET['p'], array('paths', 'overview', 'options', 'js', 'login', 'logout')) ? $_GET['p'] : 'overview'; $ss = new SimpleStats(); if (!$ss->is_installed()) { // check whether we've just finished setup if (isset($_POST['action']) && $_POST['action'] == 'complete_setup') { $ss->setup_options(); } else { $page = 'setup'; require_once SIMPLE_STATS_PATH . '/includes/setup.php'; exit; } } date_default_timezone_set($ss->options['tz']); if ($page == 'logout' || needs_authentication()) { if ($page == 'logout') { logout(); } if ($page != 'login' && !is_logged_in()) {