Home >php教程 >PHP源码 >PHP统计页面浏览次数,带文本缓存

PHP统计页面浏览次数,带文本缓存

PHP中文网
PHP中文网Original
2016-05-25 17:07:311100browse

跳至

    
    //@统计点击
    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[&#39;cfg_safe&#39;][&#39;visit-article&#39;])
            {
                file_put_contents($file, &#39;,&#39; . $id, FILE_APPEND);      
            }
            else
            {
                $string = file_get_contents($file);
                if ($string != &#39;&#39;)
                {
                    $temp = explode(&#39;,&#39;, $string);
                    foreach ($temp as $row)
                    {
                        if (empty($row))
                            continue;
                        $this->mysql->update(&#39;UPDATE `pcb_article` SET `visit` = `visit` + 1 WHERE `id` = &#39; . $row . &#39; LIMIT 1&#39;);
                    }    
                }
                unlink($file);
            } 
        }    
    }

                   

Statement:
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