English
00:00:00


How much is currently on the site.

The slider script  |  Zip unpacker  |  The script hit counter  |  Feedback script  |  Click to enlarge

AVL advertising materials rotator  |  How much is currently on the site.  |  Online program code highlighting

The script for the highlighting of program code  |  Form for uploading multiple images

Two examples of form code for uploading multiple images  |  Php handler for uploading multiple images to the server

Your comment or question

Сколько сейчас на сайте

My script counter "How much is now on the site" is simple and reliable. There are several important advantages in its favor:
1) The script works without a database, and the information is stored in a file.

2) Does not use the session, there is no extra load on the server.

3) Does not use cookies, they are often disabled by people.

4) Counts users by their ip, there is a small error in the calculation, because
how Internet providers on the same node can connect to the same ip then one,
then another Internet user. It even happens that one user at a time
the session uses multiple ip addresses. But this is rare.

There are many similar scripts on the Internet, but my one with the correct file handling.
Without errors that lead to the reset of information (account) or other consequences.

It is better to create a separate file for the script in a private folder from users and
connect it using include or require, so as not to enter a large code in
your template.

Here is the PHP code:

<?php
$ip
=getenv("REMOTE_ADDR");

if (
$ip!="") {
 
//текущее время
 
$CurrentTime time();
 
//через какое время ip удаляются
 
$LastTime time() - 600;
 
//файл, в котором храним ip и время
 
$puthcount $_SERVER["DOCUMENT_ROOT"] . "/include/seans.txt";

 
fclose(fopen($puthcount"a"));
 
$file file($puthcount);
 
 
$k 0;
 for (
$i 0$i sizeof($file); $i++) {
   
$stroka $file[$i];
   
$line explode("|"$stroka);
   if (
$line[1] > $LastTime) {
   
$ResFile[$k] = $stroka;
   
$k++;
  }
 }

 for (
$i 0$i sizeof($ResFile); $i++) {
  
$stroka $ResFile[$i];
  
$line explode("|"$stroka);
  if (
$line[0]==$ip) {
      
$line[1] = trim($CurrentTime)."\n";
      
$is_ip_in_file 1;
  }
  
$linen implode("|"$line);
  
$ResFile[$i] = $linen;
 }

 
$fol fopen($puthcount"r+");
 
flock($folLOCK_EX);
 
ftruncate ($fol0);
 
fseek ($fol0SEEK_SET);
 for (
$i 0$i sizeof($ResFile); $i++) {
  
fputs($fol$ResFile[$i]); 
  }
 
fflush($fol);
 
flock($folLOCK_UN);
 
fclose($fol);

 if (!
$is_ip_in_file) {
  
$fp fopen($puthcount"a");
  
flock($fpLOCK_EX);
  
$line $ip."|".$CurrentTime."\n";
  
fputs($fp$line);
  
fflush($fp);
  
flock($fpLOCK_UN);
  
fclose($fp);
 }
}
? >

Here is the code for displaying the invoice result on the site pages:

<?php
$koluser_online 
sizeof(file($puthcount)); 
echo 
"Сейчас на сайте: <b>"$koluser_online ."</b>";
? >

The script is free and can be installed on any number of your sites,
but you can only distribute it with a link to this site,
from the distribution site.    good Luck! Alexey.


The slider script  |  Zip unpacker  |  The script hit counter  |  Feedback script  |  Click to enlarge

AVL advertising materials rotator  |  How much is currently on the site.  |  Online program code highlighting

The script for the highlighting of program code  |  Form for uploading multiple images

Two examples of form code for uploading multiple images  |  Php handler for uploading multiple images to the server

Your comment or question

If you insert our link to your site at the address you wrote in the
comments, then your address will also become a link!