Forum Moderators: DixonJones
I've been looking for a free page counter to go on a site where each page belongs to a different person and I only want a text counter to count the visits to the one page. I do not want to have to sign up for it as there will be too many pages to put this on and I don't need email reports or anything but page views.
I found one that is very simple JS code but it is counting the hits for every page I put the counter on and adding all hits to every page.
thanks in advance,
You need some kind of server-side scripting. If you have access to PHP/SQL then the solution is trivial.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
$tempcount = 0;
while($tempcount < 8)
{
$tempcount++;
if(-e "lock/myfile1.lok")
{
sleep 2;
}
else
{
open (LOCK,">>lock/myfile1.lok");
close LOCK;
open (COUNTER,"<counter1.fil");
$count = <COUNTER>;
close COUNTER;
$count++;
open (COUNTER,">counter1.fil");
print COUNTER ($count);
close COUNTER;
unlink "lock/myfile1.lok";
last;
}
}
You need to upload this to you cgi-bin, CHMOD 755.
Also a plain text file called counter1.fil, CHMOD 777.
Then simply add pages by changing to myfile2, myfile3 and so on.
Hope this helps.
Save the following as logger.php
put it anywhere but your cgi-bin or above, home directory is fine
<?php
// full path to logs file
$log_file = "/serverpathtologfile/stats/logs.txt";
$browser=$HTTP_USER_AGENT;
$ip = getenv("REMOTE_ADDR");
$host = getenv("REMOTE_HOST");
$refer = getenv("HTTP_REFERER");
$gdate= date("n¦j¦y¦H¦i¦s¦¦z");
$cf = fopen($log_file, "a+");
fputs($cf, "$gdate¦$ip¦$host¦$refer¦$id¦$page¦$browser¦\n");
fclose($cf);
Header("Content-type:image/gif");
passthru("catclear.gif");//senda1x1gif
?>
Then put this on each page and change id to site id if you have multiple sites you want to use on
and change the page var to a page id
<IMG SRC="http://www.yourdomain.com/logger.php?id=84&page=index" border="0" width="1" height="1">
You can also create a 1x1 clear pixel gif and put it in the same directory as the script.
There is a more elaborate version that gathers user info etc via JS and and analyzer but I won't give it a way.
This is just the bare minimum for the traking part.
-Bill
I'm slow getting this set up and have a few questions re the counter code you posted earlier.
>Here is a simple perl script (the first line staering #! must be the VERY first line of the script):-
You didn't say what to name this code. I assume counter.pl is ok?
Also you said, to add more pages just change the myfile1.lok. But I'm not sure if I should add #2 under #1 or after "close LOCK:" and start another set.
open (LOCK,">>lock/myfile1.lok");
close LOCK;
open (counter,"<counter1.fil");
$count = <counter>;
>You need to upload this to you cgi-bin, CHMOD 755.
>Also a plain text file called counter1.fil, CHMOD 777.
I did these but how do I call up the counter and which one? Do I put an SSI on the page linked to counter.pl?
And do I do this for all the counters? or link it to counter 1.fil , then counter 2.fil, etc.
Thanks,
Lori