找回密码
 加入网盟
分割线
官方精品推荐
这里主要用到了session保存当前访问者,并将访问次数写入本地文件。
  1. <?   
  2.     @session_start();   
  3.     $counter = intval(file_get_contents("counter.dat"));  //创建一个dat数据文件  
  4.     if(!$_SESSION['#'])   
  5.     {   
  6.      $_SESSION['#'] = true;   
  7.      $counter++;  //刷新一次+1  
  8.      $fp = fopen("counter.dat","w");  //以写入的方式,打开文件,并赋值给变量fp  
  9.      fwrite($fp, $counter);   //将变量fp的值+1  
  10.      fclose($fp);   
  11.     }   
  12. ?>  
复制代码


输入代码
  1. <?php echo "$counter";?>  
复制代码
  1. <?php  
  2.     @session_start();   
  3.     $counter = intval(file_get_contents("counter.dat"));   
  4.     if(!$_SESSION['#'])   
  5.     {   
  6.      $_SESSION['#'] = true;   
  7.      $counter++;   
  8.      $fp = fopen("counter.dat","w");   
  9.      fwrite($fp, $counter);   
  10.      fclose($fp);   
  11.     }   
  12. ?>  
  13. <p align="center">您是到访的第<?php echo "$counter";?>位用户</p>  
复制代码


1.jpg
分享至 : QQ空间
收藏

6 个回复

正序浏览
rcx096 1 2021-1-20 14:04:36
7#
奥利给
回复 使用道具 举报
1106311624 1 2021-1-20 13:50:42
6#
感谢{author}楼主
回复 使用道具 举报
FAKER 1 2021-1-20 05:08:26
5#
{author} 感谢楼主分享
回复 使用道具 举报
青蛙 1 2021-1-19 21:43:28
4#
非常感谢
回复 使用道具 举报
db19860922 1 2021-1-19 20:28:39
3#
膜拜大神3秒钟
回复 使用道具 举报
jlgp313 1 2021-1-19 20:27:46
2#
支持,顶一下。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入网盟
关闭

华夏网盟推荐 上一条 /1 下一条