Home >Backend Development >PHP Tutorial >php 利用cookie记录访问次数

php 利用cookie记录访问次数

WBOY
WBOYOriginal
2016-07-25 08:45:451446browse
  1. $f_open = fopen("count.txt","r+"); //打开指定的文件
  2. $count = fgets($f_open); //读取文件中的数据
  3. if(empty($_COOKIE['cookie_name'])){ //判断COOKIE的是否存在
  4. setcookie("cookie_name",value,time()+1800); //如果不存在,则创建COOKIE
  5. $count = $count + 1; //将变量$count的值加1
  6. rewind($f_open); //打开指定的文件
  7. fwrite($f_open,$count); //向文件中写入新的数据
  8. fclose($f_open); //关闭文件
  9. }
  10. ?>
复制代码

php, cookie


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn