Hi all,
I'm trying to keep track of statistics on a few pages to see how many times different users (and different types of users) are accessing certain pages, but I have no way of telling if a user is actually coming to the page for the first time or just refreshing the page. Obviously, I don't want to report any stats for a user who is simply refreshing the page. Ideally, checking $HTPP_REFERER against $PHP_SELF is a good idea, but $HTTP_REFERER is unreliable (even on the machine I'm testing it on). Any suggestions?
telling if the page has been refreshed
Moderator: General Moderators
-
staypufinpc
- Forum Newbie
- Posts: 12
- Joined: Thu May 01, 2003 7:59 pm
Code: Select all
<?
session_start();
$_SESSION['times']++;
if ($_SESSION['times'] > 1){
echo "You've been here before. This is your ".$_SESSION['times']."th visit.";
} else {
echo "This is your first visit. Try to refresh.";
}
?>-
staypufinpc
- Forum Newbie
- Posts: 12
- Joined: Thu May 01, 2003 7:59 pm
thanks
Thanks, that gave me the right idea. Here's what I did:
Most of my pages are generated by some sort of function, so simply including a counter wouldn't work, because the pages bring up different records from a database, which means the counter would only mark the first record they look at (which wouldn't be true stats). Instead, I just made a variable out of the page's url, which included the id number for each record, and the username. I compare that at the beginning of the stat function to see if it matches the last url visited and, if it does, don't report the stat. Otherwise, I report it and get the true number of visits to each page by each user. Thanks for your insight.
Most of my pages are generated by some sort of function, so simply including a counter wouldn't work, because the pages bring up different records from a database, which means the counter would only mark the first record they look at (which wouldn't be true stats). Instead, I just made a variable out of the page's url, which included the id number for each record, and the username. I compare that at the beginning of the stat function to see if it matches the last url visited and, if it does, don't report the stat. Otherwise, I report it and get the true number of visits to each page by each user. Thanks for your insight.