Advertisement
Guest User

stats.php

a guest
Nov 28th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. <?php
  2. // --[Config]--------------
  3. $file = 'stats.dat';
  4. // File to store all data.
  5. $onlineTime = 180;
  6. // Max user online time (in seconds)
  7. $perPage = 20;
  8. // Entry per page
  9. // --[End Config]------
  10.  
  11. if(!file_exists($file)) {
  12. $fs = fopen($file, 'w') or die('<b>Error:</b> Unable to create stats file.<br/>');
  13. fclose($fs);
  14. }
  15. $ip = (getenv('HTTP_X_FORWARDED_FOR') != '') ? getenv('HTTP_X_FORWARDED_FOR') : $_SERVER['REMOTE_ADDR'];
  16. $ua = $_SERVER['HTTP_USER_AGENT'];
  17. $ua = explode(' ', $ua);
  18. $ua = $ua[0];
  19. $ua = str_replace('|~~|', '', htmlspecialchars($ua));
  20. $ip = str_replace('|~~|', '', htmlspecialchars($ip));
  21. $pageName = str_replace('|~~|', '', htmlspecialchars($pageName));
  22. $data = file($file);
  23. foreach($data as $i => $line) {
  24. $line = explode('|~~|', $line);
  25. if(($line[1] == $ip && $line[2] == $ua) || $line[0] < (time() - $onlineTime)) unset($data[$i]);
  26. }
  27. $data[] = implode('|~~|', array_pad(array(time(), $ip, $ua, $pageName), 5, ''));
  28. $online = count($data);
  29. $fs = fopen($file, 'w');
  30. foreach($data as $line) fputs($fs, rtrim($line) . "\n");
  31. fclose($fs);
  32. unset($data, $line, $ip, $ua, $fs);
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement