FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Php users counter script





hellojohnatan
Hi guys!
I'm so glad I found this forum as I been going nuts trying to get a good users counter for my web site. http://innovativetechnologyconcepts.com
I'm fairly new at php but know a fair bit, anyway i'm hopeing you can help me out a bit here. I own a script website that allows to check online users.
PHP Code:
Code:
<?php
    $file = "uvcounter.txt";
    unset($h);
    $f = fopen($file, "r+");
    $h = fread($f, filesize($file));
    fclose($f);
    if (!$mevisit) {
    $h++;
    $f = fopen($file, "w+");
    fwrite($f, $h);
    fclose($f);
    @setcookie("mevisit","yes",time()+31536000);
    }
    $file = "vcounter.txt";
    unset($h);
    $f = fopen($file, "r+");
    $h = fread($f, filesize($file));
    fclose($f);
    $h++;
    $f = fopen($file, "w+");
    fwrite($f, $h);
    fclose($f);
?>

Can anyone tell me what's wrong?
Thanks in advance!
rvec
Code:
<?php
$file = "uvcounter.txt";
unset($h);   // Why are you unsettings this?
$f = fopen($file, "r+"); // You only need to read, why r+?
$h = fread($f, filesize($file));
fclose($f);
if (!$mevisit) { // Where is this variable set? (I guess you mean $_COOKIE['mevisit'])
  $h++;
  $f = fopen($file, "w+");
  fwrite($f, $h);
  fclose($f);
  @setcookie("mevisit","yes",time()+31536000);
}
$file = "vcounter.txt";
unset($h); // Why unset $h again? It will be overwritten in 2 lines ...
$f = fopen($file, "r+"); // r+ again
$h = fread($f, filesize($file));
fclose($f);
$h++;
$f = fopen($file, "w+");
fwrite($f, $h);
fclose($f);
?>


What this does is set a cookie in every visitor's browser. Count pageviews in vcounter.txt and count pageviews - every users's first page view in uvcounter.txt.

If you are trying to count the active users I'd advise loggin an id with a timestamp and keeping the id in the user's session. In every page load you can check the file, count the rows where the timestamp is > (time()-5*60) to get the users that where active in the last 5 min (which is kinda what phpBB does).
sonam
If you need only online visitors without statistic then you can go on my site (in signature) and find Butterfly visitors online counter. This counter count visitors in fly every ten second and display number of active visitors on your site.

Sonam
Related topics
script backup database
Need help show how many who is online on the forum
PHP Counter?
PHP Counter
[php] travel agency script alike
one line securing of php pages (login of users) (user auth)
my PHP code benchmark script that got some problems
Question about a php and mysql script.
Help with php and java script
Free PHP/MySQL login script
anyone know of a good php form processer script
php Counter
Wanting a PHP input security script: up to 1200frih$!
PHP IP tracking script ?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.