?php session_start();
if($_SESSION[temp]==""){ //判斷$_SESSION[temp]==""的值是否為空,其中的temp為自定義的變量
if(($fp=fopen("counter.txt","r"))==false){
echo "打開文件失敗!";
}else{
$counter=fgets($fp,1024); //讀取文件中數據
fclose($fp); //關閉文本文件
$counter++; //計數器增加1
$fp=fopen("counter.txt","w"); //以寫的方式打開文本文件!---->
fputs($fp,$counter); //將新的統計數據增加1
fclose($fp);
} //關閉文
$_SESSION[temp]=1; //登錄以后,$_SESSION[temp]的值不為空,給$_SESSION[temp]賦一個值1
}
?>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=gb2312">
title>通過文本文件統計頁面訪問量/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>企業精神/strong>:博學、創新、求實、篤行/p>
p class="STYLE1">strong>公司理念/strong>:以高新技術為依托,戰略性地開發具有巨大市場潛力的高價值的產品。/p>
p class="STYLE1">strong>公司遠景/strong>:成為擁有核心技術和核心產品的高科技公司,在某些領域具有領先的市場地位。/p>
p class="STYLE1">strong>核心價值觀/strong>:永葆創業激情、每一天都在進步、容忍失敗,鼓勵創新、充分信任、平等交流。/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>
?php
//以圖形的形式輸出數據庫中的記錄數
if(($fp=fopen("counter.txt","r"))==false){
echo "打開文件失敗!";
}else{
$counter=fgets($fp,1024);
fclose($fp);
//通過GD2函數創建畫布
$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","網站的訪問量:"); //對指定的中文字符串進行轉換
$font = "Fonts/FZHCJW.TTF";
imagettftext($im,14,0,20,18,$color,$font,$text); //輸出中文
//輸出網站的訪問次數
imagestring($im,5,160,5,$counter,$color);
imagepng($im);
imagedestroy($im);
}
?>
更多關于PHP相關內容感興趣的讀者可查看本站專題:《php文件操作總結》、《PHP運算與運算符用法總結》、《PHP網絡編程技巧總結》、《PHP基本語法入門教程》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》