• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

looking for a decent counter

keith

anti-liberal
NLC
a decent one i tell you. one that doesn't suck.

it seems every counter i've tried will sooner or later reset it self to zero, even the ones i've tried with file locking. anything out there that won't continuously reset itself to zero? it must be able to be included with an ssi tag.
 
here, this one is easy, but it will count each hit


Make a file called count.inc upload it and chmod it 777

then put this in your HTML and name the doc NAME_HERE.php


replace name_here with index, or whatever


<?
$file = fopen("count.inc","r+");
$count = fread($file, filesize("count.inc"));
fclose($file);
$count += 1;
$file = fopen("count.inc","w+");
fputs($file, $count);
fclose($file);
include("count.inc");?>
 
That's a buggy script. For one, it does not lock the file. Furthermore, because the reading and writing is not atomic (you close the file between reads and writes), it is possible for your counter to miss counts or be reset to an earlier number.
 
Maybe some of the excellent programmers that know php here would like to come together and make a counter script. I've never ever come accross a good counter script and agree that there is a need for it.
 
hmm....never thought about "buggy" counters, but maybe SQL counter ??
SQL ->
PHP:
CREATE TABLE counter(count INT);
PHP ->
PHP:
<?
$link = mysql_connect("host","uset","pass");
mysql_select_db("dbname",$link);

$add_q = mysql_query("UPDATE COUNTER SET count=count+1") ;

$show_q = mysql_query("SELECT * FROM counter");

while($res = mysql_fetch_array($show_q))
print $res[count] ;
?>

:confused:
 
Originally posted by megapuzik
hmm....never thought about "buggy" counters, but maybe SQL counter ??
SQL ->
PHP:
CREATE TABLE counter(count INT);
PHP ->
PHP:
<?
$link = mysql_connect("host","uset","pass");
mysql_select_db("dbname",$link);

$add_q = mysql_query("UPDATE COUNTER SET count=count+1") ;

$show_q = mysql_query("SELECT * FROM counter");

while($res = mysql_fetch_array($show_q))
print $res[count] ;
?>

:confused:
Thank you. I shall try this a.s.a.p.
<edit>How would I find out refferers?</edit>
 
Last edited:
Back
Top