Techno

Online Counter script [ technoslab.blogspot.com ]

Mar 25th, 2011
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. ********************************************************
  5. *                                                      *
  6. * - Counter script by http://technoslab.blogspot.com   *
  7. * - Make a file 'logs.dat' and chmod it to 0777        *
  8. *                                                      *
  9. ********************************************************
  10. */
  11.  
  12. error_reporting(0);
  13.  
  14. $period = 30;
  15.  
  16. $logfile = "logs.dat";
  17.  
  18. $time = time();
  19.  
  20. $ip = $_SERVER['REMOTE_ADDR'];
  21.  
  22. $info = file_get_contents($logfile);
  23.  
  24. file_put_contents($logfile,"<info><ip>$ip</ip><time>$time</time></info>\n",FILE_APPEND);
  25.  
  26. $contents = file_get_contents($logfile);
  27.  
  28. if($contents==""){ 
  29.  
  30.     file_put_contents($logfile,"<visit>0</visit>");
  31.  
  32. }
  33.  
  34. preg_match_all("@<info><ip>(.+?)</ip><time>(.+?)</time></info>@",$contents,$match);
  35.  
  36. $num1 = count($match[0]);
  37.  
  38. preg_match("@<visit>(.+?)</visit>@",$contents,$tm);
  39.  
  40. $num2 = $tm[1];
  41.  
  42. $num = $num1 + $num2;
  43.  
  44. if(filesize($logfile)>1024*2){
  45.  
  46.     file_put_contents($logfile,"<visit>$num</visit>");
  47.  
  48. }
  49.  
  50. $old = $time - $period;
  51.  
  52. $online = 0;
  53.  
  54. $processed = array();
  55.  
  56. for($i=0;$i<$num;$i++){
  57.  
  58.     if($match[2][$i]>$old && !in_array($match[1][$i],$processed)){
  59.  
  60.         $processed[] = $match[1][$i];
  61.        
  62.         $online++;
  63.  
  64.     }
  65.  
  66. }
  67.  
  68. echo "<div style='background:url(http://s4.postimage.org/14y30hyuc/button_background.png) center repeat-x;height:20px;width:auto;float:left;font:bold 95% cursive;color:white;valign:middle;text-align:center;border:1px solid rgb(50,150,250);'>Online : $online | Visits : $num</div>";
  69.  
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment