PHP code to count page views (text cache)

WBOY
Release: 2016-07-25 08:51:47
Original
1417 people have browsed it
  1. /**
  2. @Statistics page views Text cache
  3. @site http://bbs.it-home.org
  4. *
  5. */
  6. private function visit($id)
  7. {
  8. if (isset($GLOBALS['cfg_safe']['visit-article']) && $GLOBALS['cfg_safe']['visit-article'])
  9. {
  10. $file = SYS_PATH . 'cache/visit-article.txt';
  11. if (!file_exists($file))
  12. {
  13. file_put_contents($file, ',' . $id);
  14. }
  15. else if ((time() - filectime($file)) < $GLOBALS['cfg_safe']['visit-article'])
  16. {
  17. file_put_contents($file, ',' . $id, FILE_APPEND);
  18. }
  19. else
  20. {
  21. $string = file_get_contents($file);
  22. if ($string != '')
  23. {
  24. $temp = explode(',', $string);
  25. foreach ($temp as $row)
  26. {
  27. if (empty($row))
  28. continue;
  29. $this->mysql->update('UPDATE `pcb_article` SET `visit` = `visit` + 1 WHERE `id` = ' . $row . ' LIMIT 1');
  30. }
  31. }
  32. unlink($file);
  33. }
  34. }
  35. }
复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template