PDA

View Full Version : What is the best way to track hits?



kuau
08-12-2009, 03:37 AM
I have built a site that lists all members that belong to a certain category when the viewer chooses a category from the category list. They can then click on a particular member to go to their particular page.

I would like to keep track of how many times people go to each member's page. I know there is a way to tell if someone clicks on a link because emal marketers do it, but I'm not sure how. Any help would be appreciated. Thanks. :)

bluewalrus
08-12-2009, 05:05 AM
Are you just looking for a simple number of how many times a page is viewed, or how many times each user visits a page in a set time frame?

kuau
08-12-2009, 08:37 AM
The former. I just want to monitor which links are most popular and how many people my site is sending to member sites. It doesn't matter who is clicking on them or when, just an accumulative total.

I figure that every time there is a click I run an update command such as:

UPDATE members SET hits = (hits+1) WHERE member_id = $member_id;

but how do you tell when there is a click? Do I do something with the <a href..> that lets me know? Thanks.

davelf
08-12-2009, 09:23 AM
This snippet counts the number of hits a website receives, using flat files.


<?php
<?php
//
// Make a blank file called count.txt and CHMOD it 777
//
//Lets open the file as read only (r)
$fp = fopen("count.txt","r");
// The next line reads our file into a string,
// in other words sets the contents of count.txt as $count,
// so we can do stuff with it
$count = fread ($fp, filesize ("count.txt"));
// We don't need more data from the file right now, so close it
fclose($fp);
// Now we need to increment the number in the file, using the ++ operator, +1 would work but this is nicer.
$count++;
// Now we've incremented the count, lets write it to the file
// We need to open if for writing (w)
$fp = fopen("count.txt","w");
// Now write the actual data
fwrite($fp, $count);
// And close the file
fclose($fp);
// Lets display the updated count to the users
echo "Hits : $count";
?>
?>


i got it from another site (thx to the author).

Just want to share, i hope this will help:)

kuau
08-12-2009, 10:03 AM
Dear Davelf: Thanks, that's a very useful script which I can use elsewhere. The question above is a little different because I'm not counting how many hits on the website - maybe I used the wrong word - but rather the number of clicks on a link within the website and loading it into a database. So there will be a different total for each member's link. I hope that makes it somewhat clearer. :)

JShor
08-12-2009, 02:25 PM
Well, I'd make a data source, recording IPs from the amount of clicks on that page. Every person has a unique IP address, so get the total number of remote addresses, and that would be the total number of the counter.