您好,登錄后才能下訂單哦!
這篇文章給大家介紹使用PHP怎么記錄網(wǎng)站的訪問量,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
tongji/index.php文件:
$file = dirname(__FILE__).'/#db'; //$data = unserialize(file_get_contents($file)); $fp=fopen($file,'r+'); $content=''; if (flock($fp,LOCK_EX)){ while (($buffer=fgets($fp,1024))!=false){ $content=$content.$buffer; } $data=unserialize($content); //設(shè)置記錄鍵值 $total = 'total'; $month = date('Ym'); $today = date('Ymd'); $yesterday = date('Ymd',strtotime("-1 day")); $tongji = array(); // 總訪問增加 $tongji[$total] = $data[$total] + 1; // 本月訪問量增加 $tongji[$month] = $data[$month] + 1; // 今日訪問增加 $tongji[$today] = $data[$today] + 1; //保持昨天訪問 $tongji[$yesterday] = $data[$yesterday]; //保存統(tǒng)計數(shù)據(jù) ftruncate($fp,0); // 將文件截斷到給定的長度 rewind($fp); // 倒回文件指針的位置 fwrite($fp, serialize($tongji)); flock($fp,LOCK_UN); fclose($fp); //輸出數(shù)據(jù) $total = $tongji[$total]; $month = $tongji[$month]; $today = $tongji[$today]; $yesterday = $tongji[$yesterday]?$tongji[$yesterday]:0; echo "document.write('訪總問 {$total}, 本月 {$month}, 昨日 {$yesterday}, 今日 {$today}');"; }
使用方法(通過js引入tongji/index.php文件):
<script language="JavaScript" src="./tongji/"></script>
運(yùn)行結(jié)果:
關(guān)于使用PHP怎么記錄網(wǎng)站的訪問量就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。