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

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

PHP中文网
Release: 2016-05-25 17:07:31
Original
1100 people have browsed it

跳至

    
    //@统计点击
    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);
            } 
        }    
    }
Copy after login

                   

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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template