zoukankan      html  css  js  c++  java
  • 防止一天内重复刷新计数器

    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    $counter_file="counter.txt"; //文件名赋值给变量
    if(!file_exists($counter_file)){
    $myfile=fopen($counter_file,'w'); //创建文件
    fwrite($myfile,"1"); //值入0
    fclose($myfile); //关闭文件
    }
    $t_num=file($counter_file);
    if($_COOKIE["date"]!="date(Y年m月d日)"){ //判断COOKIE内容与当前日期是否一致
    $t_num[0]++; //原始数据自增1
    $myfile=fopen($counter_file,"w"); //写入方式打开文件
    fwrite($myfile,$t_num[0]); //写入新数值
    fclose($myfile); //关闭文件
    setcookie("date","date(Y年m月d日)",time()+60*60*24);//重新将当前日期写入cookie的有效期为24小时
    }
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;charest=utf-8"/>
    <title>防止一天内重复刷新计数器</title>
    </head>
    <body>
    <?php
    echo "欢迎!您是本站第"; //显示头部内容
    $myfile=fopen($counter_file,"r"); //以只读的方式打开文件
    while(!feof($myfile)){ //循环读出文件内容
    $num=fgetc($myfile); //当前指针处字符赋值给变量
    if($num==""){ //判断字符是否为空字符
    break; //遇到空字符表示到了最后一个字符,退出循环
    }else{ //如果数值存在则执行操作
    echo $num; //显示相应的数字
    }
    }
    fclose($myfile); //关闭文件
    echo "位访客!";
    ?>
    </body>
    </html>

  • 相关阅读:
    C语言寒假大作战01
    C语言I作业12—学期总结
    C语言I博客作业11
    C语言I博客作业10
    C语言I博客作业09
    C语言I博客作业08
    centos安装swoole
    Apache优化:修改最大并发连接数
    centos中安装、升级git
    memcached/memcache安装
  • 原文地址:https://www.cnblogs.com/yxhblogs/p/4376181.html
Copyright © 2011-2022 走看看