Home >Backend Development >PHP Tutorial >An example of php website access statistics code

An example of php website access statistics code

WBOY
WBOYOriginal
2016-07-25 08:59:511687browse
Introducing a code written in PHP to count website visits. The data is saved in the local file count3.dat and called with js in the page. Friends in need can refer to it.

1. Statistics page count.php

<?php
/**
 * 网站访问统计
 * edit bbs.it-home.org
*/
function pageVisitCount(){
    $count= "count3.dat";
    $num= @file_get_contents($count);
    if ($fp= fopen($count,"w+")){
    flock($fp,LOCK_EX);
    $num++;
    fwrite($fp,$num);
    flock($fp,LOCK_UN);
    }
    return $num;
    }

    echo pageVisitCount();
?>

2. Page call



Statement:
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