本文實例講述了PHP實現(xiàn)通過文本文件統(tǒng)計頁面訪問量功能。分享給大家供大家參考,具體如下:
一 代碼
index.php
?php session_start(); if($_SESSION[temp]==""){ //判斷$_SESSION[temp]==""的值是否為空,其中的temp為自定義的變量 if(($fp=fopen("counter.txt","r"))==false){ echo "打開文件失敗!"; }else{ $counter=fgets($fp,1024); //讀取文件中數(shù)據(jù) fclose($fp); //關(guān)閉文本文件 $counter++; //計數(shù)器增加1 $fp=fopen("counter.txt","w"); //以寫的方式打開文本文件!----> fputs($fp,$counter); //將新的統(tǒng)計數(shù)據(jù)增加1 fclose($fp); } //關(guān)閉文 $_SESSION[temp]=1; //登錄以后,$_SESSION[temp]的值不為空,給$_SESSION[temp]賦一個值1 } ?> html> head> meta http-equiv="Content-Type" content="text/html; charset=gb2312"> title>通過文本文件統(tǒng)計頁面訪問量/title> style type="text/css"> !-- .STYLE1 { font-size: 12px; font-weight: bold; } body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } .STYLE2 { color: #FF0000; font-weight: bold; } --> /style> /head> body> table width="995" height="809" border="0" align="center" cellpadding="0" cellspacing="0" background="images/bg.jpg"> tr> td width="131" height="215"> /td> td width="714"> /td> td width="128"> /td> /tr> tr> td height="323"> /td> td align="center" valign="top">table width="660" height="323" border="0" cellpadding="0" cellspacing="0" background="images/bg3.jpg"> tr> td width="671" height="420">p> span class="STYLE1"> p class="STYLE1">strong>企業(yè)精神/strong>:博學(xué)、創(chuàng)新、求實、篤行/p> p class="STYLE1">strong>公司理念/strong>:以高新技術(shù)為依托,戰(zhàn)略性地開發(fā)具有巨大市場潛力的高價值的產(chǎn)品。/p> p class="STYLE1">strong>公司遠(yuǎn)景/strong>:成為擁有核心技術(shù)和核心產(chǎn)品的高科技公司,在某些領(lǐng)域具有領(lǐng)先的市場地位。/p> p class="STYLE1">strong>核心價值觀/strong>:永葆創(chuàng)業(yè)激情、每一天都在進(jìn)步、容忍失敗,鼓勵創(chuàng)新、充分信任、平等交流。/p>/td> /tr> tr> td height="40" align="center">img src="gd1.php" />/td> /tr> /table>/td> td>nbsp;/td> /tr> tr> td>nbsp;/td> td>nbsp;/td> td>nbsp;/td> /tr> /table> p>nbsp;/p> /BODY> /HTML>
gd1.php
?php //以圖形的形式輸出數(shù)據(jù)庫中的記錄數(shù) if(($fp=fopen("counter.txt","r"))==false){ echo "打開文件失敗!"; }else{ $counter=fgets($fp,1024); fclose($fp); //通過GD2函數(shù)創(chuàng)建畫布 $im=imagecreate(240,24); $gray=imagecolorallocate($im,255,255,255); $color =imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255)); //定義字體顏色 //輸出中文字符 $text=iconv("gb2312","utf-8","網(wǎng)站的訪問量:"); //對指定的中文字符串進(jìn)行轉(zhuǎn)換 $font = "Fonts/FZHCJW.TTF"; imagettftext($im,14,0,20,18,$color,$font,$text); //輸出中文 //輸出網(wǎng)站的訪問次數(shù) imagestring($im,5,160,5,$counter,$color); imagepng($im); imagedestroy($im); } ?>
二 運行結(jié)果
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php文件操作總結(jié)》、《PHP運算與運算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
標(biāo)簽:遂寧 遵義 吐魯番 武威 寧夏 常州 荊門 徐州
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP實現(xiàn)通過文本文件統(tǒng)計頁面訪問量功能示例》,本文關(guān)鍵詞 PHP,實現(xiàn),通過,文本,文件,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。