php简单计数器_PHP_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > PHP > php简单计数器

php简单计数器

 2011/12/20 10:54:36  ErnestChen  http://ernestchen.iteye.com  我要评论(0)
  • 摘要:<?php//1------cookie计数器if(isset($_COOKIE["num"])){$num=$_COOKIE["num"]+1;}else{$num=1;}setcookie("num",$num);echo"Youarethe".$num."timesvisit."."</br>";//2-------文本计数器$file="../counter/count.dat";if(!file_exists($file)){$num_txt=1;}else
  • 标签:PHP
<?php
//1------cookie计数器
if (isset($_COOKIE["num"])) {
	$num=$_COOKIE["num"]+1;
}else {
	$num=1;
}
setcookie("num",$num);
echo "You are the ".$num." times visit."."</br>";

//2-------文本计数器
$file="../counter/count.dat";
if (!file_exists($file)) {
	$num_txt=1;
}else {
	$num_txt=file_get_contents($file);
	$num_txt++;
}
$fp=fopen($file, "w");
fwrite($fp, $num_txt);
fclose($fp);
echo "You are the ".$num_txt." times visit."."</br>";

//3-------防刷新计数器
$file = "../counter/count.dat";
if (! file_exists ( $file )) {
	$fp = fopen ( $file, "w" );
	fwrite ( $fp, "0" );
	fclose ( $fp );
}
$num_txt = file_get_contents ( $file );
session_get_cookie_params ( 24 * 3600 );
session_start ();
if (! isset ( $_SESSION ["visited"] )) {
	$num_txt ++;
	$fp = fopen ( $file, "w" );
	fwrite ( $fp, $num_txt );
	fclose ( $fp );
	$_SESSION ["visited"] = "true";
}
echo "You are the " . $num_txt . " times visit." . "</br>";

//4--------图片计数器,同上,需要转杯0-9数字对应的图片
//5---------多用户计数器,存在数据库中
?>
发表评论
用户名: 匿名