Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP命中计数器文本文件值是否经常重置?_Php_Counter - Fatal编程技术网

PHP命中计数器文本文件值是否经常重置?

PHP命中计数器文本文件值是否经常重置?,php,counter,Php,Counter,我在我的网站上使用这个简单的点击计数器脚本。但它的值会重置为零或更改为较低的值,我没有注意到具体的时间间隔。脚本中是否存在任何问题。请帮忙? 根据我的假设,当用户同时访问导致文件I/O错误时,会发生此重置,从而重置文件 解决方案: 创建txt文件的及时备份,并比较值以发布计数器较高的文件中的值。 切换到数据库! <?php // SETUP YOUR COUNTER // Detailed information found in the readme.htm file

我在我的网站上使用这个简单的点击计数器脚本。但它的值会重置为零或更改为较低的值,我没有注意到具体的时间间隔。脚本中是否存在任何问题。请帮忙?


根据我的假设,当用户同时访问导致文件I/O错误时,会发生此重置,从而重置文件

解决方案:

创建txt文件的及时备份,并比较值以发布计数器较高的文件中的值。 切换到数据库!
<?php

    // SETUP YOUR COUNTER
    // Detailed information found in the readme.htm file

    // Count UNIQUE visitors ONLY? 1 = YES, 0 = NO
    $count_unique = 1;

    // Number of hours a visitor is considered as "unique"
    $unique_hours = 1;

    // Minimum number of digits shown (zero-padding). Set to 0 to disable.
    $min_digits = 5;

    #############################
    #     DO NOT EDIT BELOW     #
    #############################

    /* Turn error notices off */
    error_reporting(E_ALL ^ E_NOTICE);

    /* Get page and log file names */
    $page = input($_GET['page']) or die('ERROR: Missing page ID');
    $logfile = 'logs/' . $page . '.txt';

    /* Does the log exist? */
    if (file_exists($logfile))
    {
        /* Get current count */
        $count = intval(trim(file_get_contents($logfile))) or $count = 0;
        $cname = 'tcount_unique_'.$page;

        if ($count_unique==0 || !isset($_COOKIE[$cname]))
        {
            /* Increase the count by 1 */
            $count = $count + 1;
            $fp = @fopen($logfile,'w+') or die('ERROR: Can\'t write to the log file ('.$logfile.'), please make sure this file exists and is CHMOD to 666 (rw-rw-rw-)!');
            flock($fp, LOCK_EX);
            fputs($fp, $count);
            flock($fp, LOCK_UN);
            fclose($fp);

            /* Print the Cookie and P3P compact privacy policy */
            header('P3P: CP="NOI NID"');
            setcookie($cname, 1, time()+60*60*$unique_hours);
        }

        /* Is zero-padding enabled? */
        if ($min_digits > 0)
        {
            $count = sprintf('%0'.$min_digits.'s',$count);
        }

        /* Print out Javascript code and exit */
        echo 'document.write(\''.$count.'\');';
        exit();
    }
    else
    {
        die('ERROR: Invalid log file!');
    }

    /* This functin handles input parameters making sure nothing dangerous is passed in */
    function input($in)
    {
        $out = htmlentities(stripslashes($in));
        $out = str_replace(array('/','\\'), '', $out);
        return $out;
    }
    ?>