2015-07-02 | Code | Unlock

统计网站访问量的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;

?>

评论加载中