NameSilo

Find out how many Visitors Are online

Spaceship Spaceship
Watch
Impact
5
very Simple make a page name it whos-online.php, insert this into the page nothing else

PHP:
<?php

/*You need php but no database for this as it uses a text file. 
You can add a title, numbers of extra visitors, the refresh time and the text file.
Put this in your root dir. The text file is automatically created for you so you need to load 1 file.
Make sure the text file does not already exist.
You can include this in a page by using <?php include("what_you_named_it .php");?> for html or include("what_you_named_it.php"); for php
*/

/*This is the text you want to explain the number.
Something like;- Visitors on this page or leave blank if the text is going into your document
you need quotes " " and the semicolon ; even if this is empty */
$explain = " ";

/* Add online numbers. You can set this to 0 for actual numbers
but rather than visitors feeling lonely you can put a number in to show that nember plus the actuals
so if you put in 4 and have 2 actually on line the counter will show 6 */ 
$additions = 0;

/*This is the refresh time in minutes. For example if you use 5 your numbers
refresh every 5 minutes. The lower the number, the more accurate
it is not advisable to make this lower than 1 */ 
$timer = 10;

/* Name of the file where all the data will be saved. 
Name this something creative but it must be a text file so xxx.txt. 
make sure this name is not already in the directory. The script creates this file */
$filename = "howmanylog1.txt";

//Do not edit under this line

if (!$datei) $datei = dirname(__FILE__)."/$filename";
$time = @time();
$space = " ";
$ip = $REMOTE_ADDR;
$string = "$ip|$time\n";
$a = fopen("$filename", "a+");
fputs($a, $string);
fclose($a);

$timeout = time()-(60*$timer);

$all = "";
$i = 0;
$datei = file($filename);
for ($num = 0; $num < count($datei); $num++) {
$pieces = explode("|",$datei[$num]);

if ($pieces[1] > $timeout) {
$all .= $pieces[0];
$all .= ",";
}
$i++;
}

$all = substr($all,0,strlen($all)-1);
$arraypieces = explode(",",$all);
$useronline = count(array_flip(array_flip($arraypieces)));

// display how many people where activ within $timeout
echo $explain;
echo $space;
echo $useronline+$additions;


// Delete
$dell = "";
for ($numm = 0; $numm < count($datei); $numm++) {
$tiles = explode("|",$datei[$numm]);
if ($tiles[1] > $timeout) {
$dell .= "$tiles[0]|$tiles[1]";
}
}

if (!$datei) $datei = dirname(__FILE__)."/$filename";
$time = @time();
$ip = $REMOTE_ADDR;
$string = "$dell";
$a = fopen("$filename", "w+");
fputs($a, $string);
fclose($a);
?>

upload to your server at the root add this to your webpage


PHP:
<?php
include ("whos-online.php");
?>

this will show you the amount of people online at that time, if you have subdomains off the root and you want to add it to them do so like this:

PHP:
<?php
include ("http://www.yourwebsite.com/whos-online.php");
?>

Have fun! if its helpful please say so in my rep Thanks

Added Syntax Highlighting (PHP BBCode) - Hitch
 
Last edited by a moderator:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Could you put in [ PHP] [/PHP] tags please... (no space obviously) Makes me much easier to read.

Thanks!

P.S. Include a step saying the file it's writes to must be CHMOD'd so it is writable please :).

Edit:
PHP:
include ("http://www.yourwebsite.com/whos-online.php");
at the bottom, would be better if it was
PHP:
include ("/home/absolute/path/to/the/directory/whos-online.php");

Edit: Please post where you got it from: http://forum.statcounter.com/vb/showpost.php?p=107524&postcount=5
 
Last edited:
1
•••
I didnt get it from there. i didnt make it but its not from there a friend gave it to me
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back