Page 1 of 1

telling if the page has been refreshed

Posted: Sat Jun 28, 2003 4:55 pm
by staypufinpc
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?

Posted: Sat Jun 28, 2003 5:10 pm
by patrikG
How about using a session? SessionIDs can help you keep track of that until it times out (default is, I think, 3 hours).

Posted: Sat Jun 28, 2003 6:45 pm
by qartis

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.";
}
?>

thanks

Posted: Tue Jul 01, 2003 7:57 am
by staypufinpc
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.