php - 我的访客会话计数器不起作用
问题描述
在我的代码中,如果用户访问它会增加计数,但它会给我一个错误
/home/u845,409,439/domains/jamiatulamasolapur.org/public_html/application/views/home.php Line: 161 Function: fread File: /home/u845,409,439/domains/jamiatulamasolapur.org/public_html/application/controllers/MainController.php Line: 46 Function: view File: /home/u845,409,439/domains/jamiatulamasolapur.org/public_html/index.php Line: 315 Function: require_once
Visitor
我的代码:
<?php
// session_start();
$counter_name = "counter.txt";
// Check if a text file exists. If not create one and initialize it to zero.
if (!file_exists($counter_name)) {
$f = fopen($counter_name, "w");
fwrite($f,"0");
fclose($f);
}
// Read the current value of our counter file
$f = fopen($counter_name,"r");
$counterVal = fread($f, filesize($counter_name));
fclose($f);
// Has visitor been counted in this session?
// If not, increase counter value by one
if(!isset($_SESSION['hasVisited'])){
$_SESSION['hasVisited']="yes";
$counterVal++;
$f = fopen($counter_name, "w");
fwrite($f, $counterVal);
fclose($f);
}
echo "$counterVal";
?>
我不知道我的代码哪里错了。
解决方案
推荐阅读
- flexbox - 一个 flexbox 容器中的两个饼图
- apache-calcite - 如何将 Calcite 逻辑计划转换为另一个数据引擎的物理计划?
- java - 如何在提升基础 ci 环境中处理项目的 jira 版本和 maven 版本控制
- c# - 未捕获任务异常
- common-lisp - 打开共享对象时出错:如何嵌入共享对象或以编程方式指定不同的路径名?
- r - 将 stat_compare_means 与自己的 p.signif 标签一起使用
- openlayers - Openlayers 6 - 在线显示 Geojson 标签
- android - ChildEventListener 没有正确填充列表视图
- php - 当我尝试将 wordpress 中的自定义表单提交到模板页面时,我收到警告并且无法发布
- javascript - If 语句 - 电子邮件验证/检查