统计网站访问量的PHP代码

使用PHP统计网站的访问量

<?php

    session_start();

    if(!isset($_SESSION[‘name’])){

        $counterFile = “counter.txt”;

        $fp = fopen($counterFile,”a+”);

        $num = fgets($fp,5);

        $num=$num+1;

        print “您是第 “.”$num”.” 位访客”;

    }else{

        $counterFile = “counter.txt”;

        $fp = fopen($counterFile,”a+”);

        $num = fgets($fp,5);

        $num=$num;

        print “您是第 “.”$num”.” 位访客”;
    }

    fclose($fp);

    if(!isset($_SESSION[‘name’])){

        $fpp=fopen($counterFile,”w”);

        fwrite($fpp, $num);

        fclose($fpp);}else{exit();
    }

    $name=”test”;

    $_SESSION[‘name’]=$name;

?>
------本文结束感谢阅读------
您的支持将鼓励我继续创作!