文本形式访客计数器

function.php代码:

<?php
    function counter(){
        $file = 'counter.txt';
        if(!file_exists($file)){
            $num = 0;
            $cf = fopen($file,"w");
            fwrite($cf,$num);
            fclose($cf);
        }else{
            $cf =fopen($file,"rw");
            $num = fgetc($cf);
            fclose($cf);
        }
        $num++;
        $cf = fopen($file,"w");
        fwrite($cf,$num);
        fclose($cf);
        return $num;
    }
?>

counter.php代码:

<?php
    require("function.php");
?>
<html>
    <head>
        <title>访客计数器</title>
    </head>
    <body>
        <h1>欢迎访问</h1>
        <br>
        <font size=7 color=red><?php echo counter();?></font>
    </body>
</html>

计数器只能计数到2~10区间????

原文地址:https://www.cnblogs.com/Iwillknow/p/3426423.html