Click to See Complete Forum and Search --> : Counter


DaveKinnell
05-11-2003, 04:47 AM
Does anyone know how to make a hit counter using javascript? or is that just not possible?
Any help would be appreciated

Nevermore
05-11-2003, 07:07 AM
You need a server-side language, e.g. PHP, ASP, CGI to make a hit counter. If your server supports PHP, I have a script for you.

DaveKinnell
05-11-2003, 09:47 AM
yeah it does, but i dont know anything about php lol. i dont need any knowledge of php to use do i?

Nevermore
05-11-2003, 10:47 AM
Put this in a file and name it lctr.php:

<?php
$fh = @fopen($cfile, "r+")
or die("<BR>Failed to open file <I>$cfile</I>.");
@flock($fh, LOCK_EX)
or die("<BR>Could not lock file <I>$cfile</I>.");
$s = @fgets($fh, 6);
$count = (int) $s + 1;
$count = str_pad($count, 6);
@rewind($fh)
or die("<BR>Failed to rewind file <I>$cfile</I>.");
if (@fwrite($fh, $count) == -1)
{
die("<BR>Failed to write to file <I>$cfile</I>.");
}
@flock($fh, LOCK_UN)
or die("<BR>Could not unlock file <I>$cfile</I>.");
fclose($fh)
or die("<BR>Failed to close file <I>$cfile</I>.");
?>



and place this code in each .php file you want to count:
<?php $cfile="statcount.dat"; include "lctr.php";?> . The counter will write the number of hits to statcount.dat.

DaveKinnell
05-14-2003, 02:21 PM
thanks but er, how to i display the counter? ive never used php before so i'm probably doing something wrong lol
do i just save the lctr file in the same directory as the webpage and paste the other code or am i missing something?

Nevermore
05-14-2003, 02:24 PM
To view the number of hits just open statcount.dat. If you want to display the hit count in a page, paste this code where you want to display it:


require("statcount.dat");

lmccord2
05-14-2003, 02:39 PM
It is not possible, as cijori said. Do the code he said, or use http://www.bravenet.com 's free counters.

Nevermore
05-14-2003, 02:42 PM
am i missing something?

DaveKinnell
05-14-2003, 02:42 PM
thanks

p.s. lol@ bravenet. i have loads of bravenet stuff on my website (loooaaaads)