D
D
Dadoshik2016-10-25 20:41:49
PHP
Dadoshik, 2016-10-25 20:41:49

The online counter only sees two, what's the problem?

There is a counter code

<?php
session_start();
//выделяем уникальный идентификатор сессии
$id = session_id();

if ($id!="") {
//текущее время
$CurrentTime = time();
//через какое время сессии удаляются
$LastTime = time() - 600;
//файл, в котором храним идентификаторы и время
$base = "session.txt";

$file = file($base);
$k = 0;
for ($i = 0; $i < sizeof($file); $i++) {
$line = explode("|", $file[$i]);
if ($line[1] > $LastTime) {
$ResFile[$k] = $file[$i];
$k++;
}
}

for ($i = 0; $i<sizeof($ResFile); $i++) {
$line = explode("|", $ResFile[$i]);
if ($line[0]==$id) {
$line[1] = trim($CurrentTime)."\n";
$is_sid_in_file = 1;
}
$line = implode("|", $line); $ResFile[$i] = $line;
}

$fp = fopen($base, "w");
for ($i = 0; $i<sizeof($ResFile); $i++) { fputs($fp, $ResFile[$i]); }
fclose($fp);

if (!$is_sid_in_file) {
$fp = fopen($base, "a-");
$line = $id."|".$CurrentTime."\n";
fputs($fp, $line);
fclose($fp);
}
}
?>

But the problem is, when displaying on the page, there are always 2 online, in session.txt it enters only two, and no matter how many people are on the site, there are always two!
What could be the problem?
Or does anyone have other examples of simple counters?
I will be grateful :)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question