home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 May / INTERNET103.ISO / pc / software / windows / building / php_nuke / html / includes / counter.php next >
Encoding:
PHP Script  |  2002-09-16  |  5.4 KB  |  115 lines

  1. <?php
  2.  
  3. /************************************************************************/
  4. /* PHP-NUKE: Web Portal System                                          */
  5. /* ===========================                                          */
  6. /*                                                                      */
  7. /* Copyright (c) 2002 by Francisco Burzi                                */
  8. /* http://phpnuke.org                                                   */
  9. /*                                                                      */
  10. /* Enhanced with NukeStats Module Version 1.0                           */
  11. /* ==========================================                           */
  12. /* Copyright ⌐2002 by Harry Mangindaan (sens@indosat.net) and           */
  13. /*                    Sudirman (sudirman@akademika.net)                 */
  14. /* http://www.nuketest.com                                              */
  15. /*                                                                      */
  16. /* This program is free software. You can redistribute it and/or modify */
  17. /* it under the terms of the GNU General Public License as published by */
  18. /* the Free Software Foundation; either version 2 of the License.       */
  19. /************************************************************************/
  20.  
  21. if (eregi("counter.php",$PHP_SELF)) {
  22.     Header("Location: index.php");
  23.     die();
  24. }
  25. require_once("mainfile.php");
  26. global $prefix, $dbi;
  27.  
  28. /* Get the Browser data */
  29.  
  30. if((ereg("Nav", getenv("HTTP_USER_AGENT"))) || (ereg("Gold", getenv("HTTP_USER_AGENT"))) || (ereg("X11", getenv("HTTP_USER_AGENT"))) || (ereg("Mozilla", getenv("HTTP_USER_AGENT"))) || (ereg("Netscape", getenv("HTTP_USER_AGENT"))) AND (!ereg("MSIE", getenv("HTTP_USER_AGENT")) AND (!ereg("Konqueror", getenv("HTTP_USER_AGENT"))))) $browser = "Netscape";
  31. elseif(ereg("MSIE", getenv("HTTP_USER_AGENT"))) $browser = "MSIE";
  32. elseif(ereg("Lynx", getenv("HTTP_USER_AGENT"))) $browser = "Lynx";
  33. elseif(ereg("Opera", getenv("HTTP_USER_AGENT"))) $browser = "Opera";
  34. elseif(ereg("WebTV", getenv("HTTP_USER_AGENT"))) $browser = "WebTV";
  35. elseif(ereg("Konqueror", getenv("HTTP_USER_AGENT"))) $browser = "Konqueror";
  36. elseif((eregi("bot", getenv("HTTP_USER_AGENT"))) || (ereg("Google", getenv("HTTP_USER_AGENT"))) || (ereg("Slurp", getenv("HTTP_USER_AGENT"))) || (ereg("Scooter", getenv("HTTP_USER_AGENT"))) || (eregi("Spider", getenv("HTTP_USER_AGENT"))) || (eregi("Infoseek", getenv("HTTP_USER_AGENT")))) $browser = "Bot";
  37. else $browser = "Other";
  38.  
  39. /* Get the Operating System data */
  40.  
  41. if(ereg("Win", getenv("HTTP_USER_AGENT"))) $os = "Windows";
  42. elseif((ereg("Mac", getenv("HTTP_USER_AGENT"))) || (ereg("PPC", getenv("HTTP_USER_AGENT")))) $os = "Mac";
  43. elseif(ereg("Linux", getenv("HTTP_USER_AGENT"))) $os = "Linux";
  44. elseif(ereg("FreeBSD", getenv("HTTP_USER_AGENT"))) $os = "FreeBSD";
  45. elseif(ereg("SunOS", getenv("HTTP_USER_AGENT"))) $os = "SunOS";
  46. elseif(ereg("IRIX", getenv("HTTP_USER_AGENT"))) $os = "IRIX";
  47. elseif(ereg("BeOS", getenv("HTTP_USER_AGENT"))) $os = "BeOS";
  48. elseif(ereg("OS/2", getenv("HTTP_USER_AGENT"))) $os = "OS/2";
  49. elseif(ereg("AIX", getenv("HTTP_USER_AGENT"))) $os = "AIX";
  50. else $os = "Other";
  51.  
  52. /* Save on the databases the obtained values */
  53.  
  54. sql_query("update ".$prefix."_counter set count=count+1 where (type='total' and var='hits') or (var='$browser' and type='browser') or (var='$os' and type='os')", $dbi);
  55.  
  56. /* Start Detailed Statistics */
  57.  
  58. $dot = date("d-m-Y-H");
  59. $now = explode ("-",$dot);
  60. $nowHour = $now[3];
  61. $nowYear = $now[2];
  62. $nowMonth = $now[1];
  63. $nowDate = $now[0];
  64.  
  65. $resultyear = sql_query("select year from ".$prefix."_stats_year where year='$nowYear'",$dbi);
  66. $jml = sql_num_rows($resultyear,$dbi);
  67. if ($jml <= 0) {
  68.     sql_query("insert into ".$prefix."_stats_year values('$nowYear','0')",$dbi);
  69.     for ($i=1;$i<=12;$i++) {
  70.     sql_query("insert into ".$prefix."_stats_month values('$nowYear','$i','0')",$dbi);
  71.     if ($i == 1) $TotalDay = 31;
  72.     if ($i == 2) {
  73.         /*
  74.         if (date("L") == true) {
  75.         $TotalDay = 29;
  76.         } else {
  77.         $TotalDay = 28;
  78.         }
  79.         */
  80.         if (($nowYear % 4) == 0) {
  81.         $TotalDay = 28;
  82.         } else {
  83.         $TotalDay = 29;
  84.         }
  85.     }
  86.     if ($i == 3) $TotalDay = 31;
  87.     if ($i == 4) $TotalDay = 30;
  88.     if ($i == 5) $TotalDay = 31;
  89.     if ($i == 6) $TotalDay = 30;
  90.     if ($i == 7) $TotalDay = 31;
  91.     if ($i == 8) $TotalDay = 31;
  92.     if ($i == 9) $TotalDay = 30;
  93.     if ($i == 10) $TotalDay = 31;
  94.     if ($i == 11) $TotalDay = 30;
  95.     if ($i == 12) $TotalDay = 31;
  96.     for ($k=1;$k<=$TotalDay;$k++) {
  97.         sql_query("insert into ".$prefix."_stats_date values('$nowYear','$i','$k','0')",$dbi);
  98.     }
  99.     }
  100. }
  101.  
  102. $resulthour = sql_query("select hour from ".$prefix."_stats_hour where (year='$nowYear') and (month='$nowMonth') and (date='$nowDate')",$dbi);
  103.  
  104. if (sql_num_rows($resulthour,$dbi) <= 0) {
  105.     for ($z = 0;$z<=23;$z++) {
  106.     sql_query("insert into ".$prefix."_stats_hour values('$nowYear','$nowMonth','$nowDate','$z','0')",$dbi);
  107.     }
  108. }
  109.  
  110. sql_query("update ".$prefix."_stats_year set hits=hits+1 where year='$nowYear'",$dbi);
  111. sql_query("update ".$prefix."_stats_month set hits=hits+1 where (year='$nowYear') and (month='$nowMonth')",$dbi);
  112. sql_query("update ".$prefix."_stats_date set hits=hits+1 where (year='$nowYear') and (month='$nowMonth') and (date='$nowDate')",$dbi);
  113. sql_query("update ".$prefix."_stats_hour set hits=hits+1 where (year='$nowYear') and (month='$nowMonth') and (date='$nowDate') and (hour='$nowHour')",$dbi);
  114.  
  115. ?>