PHP统计页面浏览次数,带文本缓存
程序员文章站
2024-01-02 22:45:28
...
跳至
//@统计点击 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); } } }