// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // 10 Dec 2004 - Initial version. // 12 Dec 2004 - Table titles. // 15 Dec 2004 - Small improvements. // ////////////////////////////////////////////////////////////////////// // // Rumen Avramov // HTML Validator compatibility added. // Counter Code/JavaScript rewritten. // ////////////////////////////////////////////////////////////////////// include_once("libphp/PHPCounter/defs.php"); include_once("libphp/other.util.inc.php"); $version = "1.3.0"; $font = ""; $font_header = ""; $GLOBALS["_phpcounter_db"] = new mysqli($dbhost,$dbuser,$dbpass,$dbname); if($GLOBALS["_phpcounter_db"]->connect_error) die("Could not connect to mysql"); if(utf8_substr($counter_url,-1)!="/") $counter_url .= "/"; function phpcounter($name) { $LocalPage = $_SERVER["HTTP_REFERER"]; $Referer = $_SERVER["HTTP_REFERER"]; if(($qs=strstr($LocalPage,"?"))!="") $LocalPage = utf8_substr($LocalPage, 0, strlen($LocalPage)-strlen($qs)); $phpcounter_id = 1; $YY = date("Y-00-00"); $YYMM = date("Y-m-00"); $YYMMDD = date("Y-m-d"); $YYMMDDHHMMSS = date("Y-m-d H:i:s"); $HH = date("H"); $WD = date("w"); $unique_inc = 0; $host = gethostbyaddr($_SERVER["REMOTE_ADDR"]); if($host==$_SERVER["REMOTE_ADDR"]) $host = ""; $tld = strtolower(utf8_substr(strrchr($host,"."),1)); $array = parse_url($Referer); $referer_domain = strtolower($array["host"]); $array = parse_url($LocalPage); $local_domain = strtolower($array["host"]); $local_page = $LocalPage; $rs = mysqli_query($GLOBALS["_phpcounter_db"], "select * from phpcounter_hits where phpcounter_id='$phpcounter_id' and ip='$_SERVER[REMOTE_ADDR]' and date>='$YYMMDD 00:00:00' and date<='$YYMMDD 23:59:59'"); $hit = mysqli_fetch_array($rs); if(!$hit) { $unique_inc = 1; mysqli_query($GLOBALS["_phpcounter_db"], "insert into phpcounter_hits (phpcounter_id, date, ip, host, user_agent, referer, language) values ('$phpcounter_id', '$YYMMDDHHMMSS', '$_SERVER[REMOTE_ADDR]', '$host', '$_SERVER[HTTP_USER_AGENT]', '$Referer', '$_SERVER[HTTP_ACCEPT_LANGUAGE]')"); $phpcounter_hit_id = mysqli_insert_id($GLOBALS["_phpcounter_db"]); } else $phpcounter_hit_id = $hit["phpcounter_hit_id"]; mysqli_query($GLOBALS["_phpcounter_db"], "update phpcounter_hits set count=count+1 where phpcounter_hit_id='$phpcounter_hit_id'"); mysqli_query($GLOBALS["_phpcounter_db"], "insert into phpcounter_dates (phpcounter_id, date) values ('$phpcounter_id', '$YY')"); mysqli_query($GLOBALS["_phpcounter_db"], "update phpcounter_dates set count=count+1, unique_count=unique_count+'$unique_inc' where phpcounter_id='$phpcounter_id' and date='$YY'"); mysqli_query($GLOBALS["_phpcounter_db"], "insert into phpcounter_dates (phpcounter_id, date) values ('$phpcounter_id', '$YYMM')"); mysqli_query($GLOBALS["_phpcounter_db"], "update phpcounter_dates set count=count+1, unique_count=unique_count+'$unique_inc' where phpcounter_id='$phpcounter_id' and date='$YYMM'"); mysqli_query($GLOBALS["_phpcounter_db"], "insert into phpcounter_dates (phpcounter_id, date) values ('$phpcounter_id', '$YYMMDD')"); mysqli_query($GLOBALS["_phpcounter_db"], "update phpcounter_dates set count=count+1, unique_count=unique_count+'$unique_inc' where phpcounter_id='$phpcounter_id' and date='$YYMMDD'"); mysqli_query($GLOBALS["_phpcounter_db"], "insert into phpcounter_countries (phpcounter_id, tld) values ('$phpcounter_id', '$tld')"); mysqli_query($GLOBALS["_phpcounter_db"], "update phpcounter_countries set count=count+1, unique_count=unique_count+'$unique_inc' where phpcounter_id='$phpcounter_id' and tld='$tld'"); mysqli_query($GLOBALS["_phpcounter_db"], "insert into phpcounter_hours (phpcounter_id, `hour`) values ('$phpcounter_id', '$HH')"); mysqli_query($GLOBALS["_phpcounter_db"], "update phpcounter_hours set count=count+1, unique_count=unique_count+'$unique_inc' where phpcounter_id='$phpcounter_id' and `hour`='$HH'"); mysqli_query($GLOBALS["_phpcounter_db"], "insert into phpcounter_weekdays (phpcounter_id, weekday) values ('$phpcounter_id', '$WD')"); mysqli_query($GLOBALS["_phpcounter_db"], "update phpcounter_weekdays set count=count+1, unique_count=unique_count+'$unique_inc' where phpcounter_id='$phpcounter_id' and weekday='$WD'"); if($Referer!="") { mysqli_query($GLOBALS["_phpcounter_db"], "insert into phpcounter_referers (phpcounter_id, referer) values ('$phpcounter_id', '$Referer')"); mysqli_query($GLOBALS["_phpcounter_db"], "update phpcounter_referers set count=count+1, unique_count=unique_count+'$unique_inc', date=now() where phpcounter_id='$phpcounter_id' and referer='$Referer'"); if($referer_domain!="") { mysqli_query($GLOBALS["_phpcounter_db"], "insert into phpcounter_referer_domains (phpcounter_id, domain) values ('$phpcounter_id', '$referer_domain')"); mysqli_query($GLOBALS["_phpcounter_db"], "update phpcounter_referer_domains set count=count+1, unique_count=unique_count+'$unique_inc' where phpcounter_id='$phpcounter_id' and domain='$referer_domain'"); } } if($local_domain!="") { mysqli_query($GLOBALS["_phpcounter_db"], "insert into phpcounter_local_domains (phpcounter_id, domain) values ('$phpcounter_id', '$local_domain')"); mysqli_query($GLOBALS["_phpcounter_db"], "update phpcounter_local_domains set count=count+1, unique_count=unique_count+'$unique_inc' where phpcounter_id='$phpcounter_id' and domain='$local_domain'"); } if($local_page!="") { mysqli_query($GLOBALS["_phpcounter_db"], "insert into phpcounter_local_pages (phpcounter_id, page) values ('$phpcounter_id', '$local_page')"); mysqli_query($GLOBALS["_phpcounter_db"], "update phpcounter_local_pages set count=count+1, unique_count=unique_count+'$unique_inc' where phpcounter_id='$phpcounter_id' and page='$local_page'"); } $langs = split_langs($_SERVER["HTTP_ACCEPT_LANGUAGE"]); foreach($langs as $lang) { mysqli_query($GLOBALS["_phpcounter_db"], "insert into phpcounter_languages (phpcounter_id, lang) values ('$phpcounter_id', '$lang')"); mysqli_query($GLOBALS["_phpcounter_db"], "update phpcounter_languages set count=count+1, unique_count=unique_count+'$unique_inc' where phpcounter_id='$phpcounter_id' and lang='$lang'"); } if($_SERVER["HTTP_VIA"]!="") { mysqli_query($GLOBALS["_phpcounter_db"], "insert into phpcounter_proxies (phpcounter_id, ip, via) values ('$phpcounter_id', '$_SERVER[REMOTE_ADDR]', '$_SERVER[HTTP_VIA]')"); mysqli_query($GLOBALS["_phpcounter_db"], "update phpcounter_proxies set count=count+1, unique_count=unique_count+'$unique_inc' where phpcounter_id='$phpcounter_id' and ip='$_SERVER[REMOTE_ADDR]'"); } } function phpcounter_stats($name, $action, $pages=false,$color='') { global $l, $strings, $color_table_header, $font, $font_header,$font_color, $month_names, $bgcolor1, $bgcolor2, $page, $weekday_names,$weekday_names_short; $rs = mysqli_query($GLOBALS["_phpcounter_db"], "select * from phpcounters LIMIT 1"); $phpcounter = mysqli_fetch_array($rs); if(!$phpcounter) die("Bad counter name."); $phpcounter_id = $phpcounter["phpcounter_id"]; $pagesize = 30; $count = 0; if($action=="years") { phpcounter_box_begin($strings["years"],$pages,$color); $rs = mysqli_query($GLOBALS["_phpcounter_db"], "select * from phpcounter_dates where phpcounter_id='$phpcounter_id' and date like '%-00-00' order by date desc limit 10, 1"); $row = mysqli_fetch_array($rs); $rs = mysqli_query($GLOBALS["_phpcounter_db"], "select * from phpcounter_dates where phpcounter_id='$phpcounter_id' and date like '%-00-00'". ($pages?"":" and phpcounter_date_id>='$row[phpcounter_date_id]'"). " order by date asc"); seek($rs, $page, $pagesize); ?> intval($row["count"])) $min = intval($row["count"]); if($min=='' || $min>intval($row["unique_count"])) $min = intval($row["unique_count"]); if($max=='' || $max =$pagesize) break; } if($pages) { ?> >> ='$row[phpcounter_date_id]'"). " order by date asc"); seek($rs, $page, $pagesize); ?> intval($row["count"])) $min = intval($row["count"]); if($min=='' || $min>intval($row["unique_count"])) $min = intval($row["unique_count"]); if($max=='' || $max =$pagesize) break; } if($pages) { ?> >> '$row[phpcounter_date_id]'"). " order by date asc"); seek($rs, $page, $pagesize); ?> intval($row["count"])) $min = intval($row["count"]); if($min=='' || $min>intval($row["unique_count"])) $min = intval($row["unique_count"]); if($max=='' || $max 0 =$pagesize) break; } $average = round(($max-$min)/2); $average_low = round(($max-$min)/3); $average_high = $average+round(($max-$min)/3); if($pages) { ?> >> intval($row["count"])) $min = intval($row["count"]); if($min=='' || $min>intval($row["unique_count"])) $min = intval($row["unique_count"]); if($max=='' || $max 0 0 00:00 - 01:00   ID >>   TLD >> ='$row[phpcounter_hit_id]' order by phpcounter_hits.date asc"); } ?> IP .. : $lang){ $rs2 = mysqli_query($GLOBALS["_phpcounter_db"], "select * from phpcounter_language_defs where lang='$lang'"); $language = mysqli_fetch_array($rs2); ?>: =$pagesize) break; } if($pages) { ?> >>