<?php $f_open = fopen("count.txt","r "); //打开指定的文件 $count = fgets($f_open); //读取文件中的数据 if(empty($_COOKIE['COOKIE_name'])){ //判断COOKIE的是否存在 setcookie("cookie_name",value,time() 1800); //如果不存在,则创建COOKIE $count = $count 1; //将变量$count的值加1 rewind($f_open); //打开指定的文件 fwrite($f_open,$count); //向文件中写入新的数据 fclose($f_open); //关闭文件 } ?> <HTML> <HEAD> <TITLE>通过COOKIE统计网站的访问量</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"> <style type="text/css"> <!-- .STYLE1 {font-size: 12px} .STYLE2 {color: #FF0000} --> </style> </HEAD> <BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0> <!-- ImageReady Slices (图书管理系统浏览目录修改.jpg) --> <TABLE WIDTH=1003 BORDER=0 CELLPADDING=0 CELLSPACING=0> <TR> <TD><img src="http://img.studyofnet.comimages/bg.jpg" width="1003" height="119"></TD> </TR> <TR> <TD height="32" background="images/bg1.jpg"> <span class="STYLE1">此时是: <script language = "JavaScript" type = "text/javascript"> </script> 您已经是<span class="STYLE2">第<?php $f_open = fopen("count.txt","r "); //打开指定的文件 $count = fgets($f_open); //读取文件中的数据 echo "$count"; //输出文件中的数据 ?>次</span>访问本系统!</span></TD> </TR> </TABLE> <!-- End ImageReady Slices --> </BODY> </HTML>
,