Forum Moderators: DixonJones

Message Too Old, No Replies

free page counter

need separate page counters on each page

         

Lorel

2:04 am on Jan 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi All,

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,

dcrombie

9:57 am on Jan 8, 2004 (gmt 0)



You can't use JavaScript for a hit-counter. The script is probably using a cookie to add up YOUR visits to those pages - another user will see the counter start from '0' on the same pages.

You need some kind of server-side scripting. If you have access to PHP/SQL then the solution is trivial.

Lorel

4:15 pm on Jan 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks for explaining.

Yes I do have access to server side scripting but I don't know how to write it. Do you know where I can get free script already written?

thanks,
lori

Philip_M

6:46 pm on Jan 9, 2004 (gmt 0)

10+ Year Member



Here is a simple perl script (the first line staering #! must be the VERY first line of the script):-

#!/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.

Lorel

9:08 pm on Jan 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks Phillip, I'll give it a try. It looks like it might work.

Lori

cyber1

12:01 pm on Jan 18, 2004 (gmt 0)



I highly recommend using PHP
Its simplicity is unmatched
and for something like a counter you can't beat it.

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

Lorel

9:41 pm on Feb 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi Phillip,

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