>  기사  >  백엔드 개발  >  페이지 조회수를 계산하는 PHP 코드(텍스트 캐시)

페이지 조회수를 계산하는 PHP 코드(텍스트 캐시)

WBOY
WBOY원래의
2016-07-25 08:51:471369검색
  1. /**
  2. @统计页面浏览次数 文本缓存
  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. }
复制代码


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.