用php写个简单的计数器

来源:互联网 发布:怎么查看淘宝店铺流量 编辑:程序博客网 时间:2024/04/26 04:08
<?phpfunction jsq(){$arr = explode("/",$_SERVER["PHP_SELF"]);//获取当前文件的位置信息并以“/”分割存入数组中$datfile = $arr[count($arr)-1].".dat";//设置文件位置if(!file_exists($datfile)){//如果文件不存在$cf = fopen($datfile,"w");//建立计数器文件fputs($cf,"0");//初始化值为0fclose($cf);//关闭文件}else{//文件存在则取回计数器里的数据$cf = fopen($datfile,"r");$counter = trim(fgets($cf,10));//读取10个长度的字符fclose($cf);}$counter++;//把计数器自增1$cf = fopen($datfile,"w");//写入新数据fputs($cf,$counter);//将字符$counter写入打开的文件fclose($cf);return $counter;?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns=" http://www.w3.org/1999/xhtml"><head><title>web计数器</title><meta http-equiv="Content-Type" content="text/html" charset=utf-8 /></head><body>您是的第<?php echo jsq(); ?>位网友</body></html>

0 0
原创粉丝点击