php统计页面浏览次数(文本缓存)的代码
时间:2021-07-01 10:21:17
帮助过:19人阅读
- /**
- @统计页面浏览次数 文本缓存
- @site http://bbs.it-home.org
- *
- */
- private function visit($id)
- {
- if (isset($GLOBALS['cfg_safe']['visit-article']) && $GLOBALS['cfg_safe']['visit-article'])
- {
- $file = SYS_PATH . 'cache/visit-article.txt';
-
- if (!file_exists($file))
- {
- file_put_contents($file, ',' . $id);
- }
- else if ((time() - filectime($file)) < $GLOBALS['cfg_safe']['visit-article'])
- {
- file_put_contents($file, ',' . $id, FILE_APPEND);
- }
- else
- {
- $string = file_get_contents($file);
- if ($string != '')
- {
- $temp = explode(',', $string);
- foreach ($temp as $row)
- {
- if (empty($row))
- continue;
- $this->mysql->update('UPDATE `pcb_article` SET `visit` = `visit` + 1 WHERE `id` = ' . $row . ' LIMIT 1');
- }
- }
- unlink($file);
- }
- }
- }
|