login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Statistieken > Statistieken script

Statistieken script

Auteur: XenoX - 26 augustus 2004 - 15:02 - Gekeurd door: Dennisvb - Hits: 11737 - Aantal punten: 3.88 (8 stemmen)




Dit script laat een totaal van de statistieken zien en per dag de hits en unieke hits.

Deze tabel heb je nodig:
  1. CREATE TABLE `stats` (
  2. `ip` varchar(20) NOT NULL default '',
  3. `datum` date NOT NULL default '0000-00-00',
  4. `hits` int(10) NOT NULL default '1'
  5. ) TYPE=MyISAM;



Voorbeeld:
Include stats.php in bijvoorbeeld index.php

En zet index.php in de map stats/

De plaatjes kun je hier downloaden:
http://www.xenox-designs.net/other/stats.zip

Code:
config.php:
  1. <?php
  2. $conf['MysqlHost'] = "localhost"; // Mysql host (meestal localhost)
  3. $conf['MysqlUser'] = "root"; // Mysql gebruiker
  4. $conf['MysqlPass'] = ""; // Mysql wachtwoord
  5. $conf['MysqlDb'] = ""; // Mysql database
  6.  
  7. ###########################################
  8.  
  9. $conf['Titel'] = "you site.com"; // Titel van je site
  10. $conf['Totaal'] = TRUE; // TRUE als hij het totaal moet laten zien en FALSE als dat niet moet
  11. $conf['Limit'] = 30; // Van hoeveel dagen moet hij de statistieken laten zien
  12. ?>


stats.php
  1. <?php
  2. include("config.php");
  3.  
  4. mysql_connect($conf['MysqlHost'], $conf['MysqlUser'], $conf['MysqlPass']);
  5. mysql_select_db($conf['MysqlDb']);
  6.  
  7. $query = mysql_query("SELECT * FROM stats WHERE ip = '".$_SERVER['REMOTE_ADDR']."' AND datum = '".date("Y-m-d")."'") or die(mysql_error());
  8. $count = mysql_num_rows($query);
  9.  
  10. if($count == 0) {
  11. $query = "INSERT INTO stats (ip, datum, hits) VALUES ('".$_SERVER['REMOTE_ADDR']."', '".date("Y-m-d")."', '1')";
  12. } else {
  13. $obj = mysql_fetch_object($query);
  14. $hits = $obj->hits + 1;
  15. $query = "UPDATE stats SET hits = '".$hits."' WHERE ip = '".$_SERVER['REMOTE_ADDR']."' AND datum = '".date("Y-m-d")."'";
  16. }
  17.  
  18. mysql_query($query) or die(mysql_error());
  19. ?>


index.php
  1. <?php
  2.  
  3.  
  4. include("config.php");
  5.  
  6. mysql_connect($conf['MysqlHost'], $conf['MysqlUser'], $conf['MysqlPass']);
  7. mysql_select_db($conf['MysqlDb']);
  8. ?>
  9. <html>
  10.  
  11. <head>
  12. <title>Statistieken :: <?php echo $conf['Titel']; ?></title>
  13. <style>
  14. body, td { font-family: Verdana; font-size: x-small; }
  15. </style>
  16. </head>
  17.  
  18. <body>
  19.  
  20. <center>
  21. <?php
  22. if($conf['Totaal']) {
  23. $query = mysql_query("SELECT * FROM stats GROUP BY ip") or die(mysql_error());
  24. $uhits = mysql_num_rows($query);
  25.  
  26. $hits = mysql_result(mysql_query("SELECT sum(hits) as total FROM stats"), 0, "total");
  27.  
  28. $query = mysql_query("SELECT * FROM stats GROUP BY datum") or die(mysql_error());
  29. $delen = mysql_num_rows($query);
  30.  
  31. $total = $uhits + $hits;
  32.  
  33. $bar1 = round($hits / $total * 100);
  34. $bar2 = round($uhits / $total * 100);
  35. ?>
  36. <table border="0" cellpadding="5" cellspacing="0" width="100%" style="border: 1px solid #DDDDDD;">
  37. <tr>
  38. <td colspan="2" style="border-bottom: 1px dashed #DDDDDD;" bgcolor="#EFEFEF"><b>Totaal</b></td>
  39. </tr>
  40. <tr>
  41. <td width="140">Hits: (<?php echo $hits; ?>)</td>
  42. <td><img src="bar_line.gif" width="1" height="15"><img src="bar_1.gif" width="<?php echo $bar1; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"><img src="bar_2.gif" width="<?php echo $bar2 - 1; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"></td>
  43. </tr>
  44. <tr>
  45. <td width="140" bgcolor="#EFEFEF">Unieke hits: (<?php echo $uhits; ?>)</td>
  46. <td bgcolor="#EFEFEF"><img src="bar_line.gif" width="1" height="15"><img src="bar_1.gif" width="<?php echo $bar2; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"><img src="bar_2.gif" width="<?php echo $bar1 - 1; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"></td>
  47. </tr>
  48. </table>
  49. <br>
  50. <?php
  51. }
  52.  
  53. $select1 = mysql_query("SELECT * FROM stats GROUP BY datum ORDER BY datum DESC LIMIT 0,".$conf['Limit']) or die (mysql_error());
  54.  
  55. while($get = mysql_fetch_object($select1)) {
  56. $select = mysql_query("SELECT * FROM stats WHERE datum = '".$get->datum."'") or die (mysql_error());
  57. $uhits = mysql_num_rows($select);
  58.  
  59. $hits = mysql_result(mysql_query("SELECT sum(hits) as total FROM stats WHERE datum = '".$get->datum."'"), 0, "total");
  60.  
  61. $total = $uhits + $hits;
  62.  
  63. $bar1 = $hits / $total * 100;
  64. $bar2 = $uhits / $total * 100;
  65.  
  66. $date = explode("-", $get->datum);
  67. ?>
  68. <table border="0" cellpadding="5" cellspacing="0" width="100%" style="border: 1px solid #DDDDDD;">
  69. <tr>
  70. <td colspan="2" style="border-bottom: 1px dashed #DDDDDD;" bgcolor="#EFEFEF"><b><?php echo $date[2]."-".$date[1]."-".$date[0]; ?></b></td>
  71. </tr>
  72. <tr>
  73. <td width="140">Hits: (<?php echo $hits; ?>)</td>
  74. <td><img src="bar_line.gif" width="1" height="15"><img src="bar_1.gif" width="<?php echo $bar1; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"><img src="bar_2.gif" width="<?php echo $bar2 - 1; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"></td>
  75. </tr>
  76. <tr>
  77. <td width="140" bgcolor="#EFEFEF">Unieke hits: (<?php echo $uhits; ?>)</td>
  78. <td bgcolor="#EFEFEF"><img src="bar_line.gif" width="1" height="15"><img src="bar_1.gif" width="<?php echo $bar2; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"><img src="bar_2.gif" width="<?php echo $bar1 - 1; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"></td>
  79. </tr>
  80. </table>
  81. <br>
  82. <?php
  83. }
  84. ?>
  85. Statistieken script gemaakt door: XenoX Designs
  86. </center>
  87.  
  88. </body>
  89.  
  90. </html>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (9)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.059s