首页 > 解决方案 > 我的访客会话计数器不起作用

问题描述

在我的代码中,如果用户访问它会增加计数,但它会给我一个错误

/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";

?>

我不知道我的代码哪里错了。

标签: phpcodeigniter

解决方案


推荐阅读