问题
hiks ... im stack again ...
I try to make a simple visitor statistic, and i have a problem.
How to make the statistic don't update if user refresh the page ?
here my snippet
public function saveData($sid)
{
global $database;
$reff = parse_url($_SERVER['HTTP_REFERER']);
$referrer = isset($reff['host']) ? $reff['host'] : 'direct';
$own = $_SERVER['HTTP_HOST'];
if($referrer!=$own){
$ip = ip2long($_SERVER['REMOTE_ADDR']);
$time = time();
$page = $_SERVER['REQUEST_URI'];
$add = $database->tableAdd("eu_shop_pageview", "shop_id, ip, timestamp, page, referrer", "'$sid', '$ip', '$time', '$page', '$referrer'");
}
}
thanks :)
Regards, Stecy
回答1:
Personally, when I do view tracking, I have the following columns:
`id`
`identifier` : this is either the person's username or if they don't have an account, their IP
`date` : inserted using CURDATE()
`page_url`
Before adding to this table, I run the following query and if there are no rows returned, then I insert into that table to add a view to that page:
SELECT id FROM views WHERE identifier = '$user_id' AND date = CURDATE() AND page_url = '$url' LIMIT 1
You would want to change how you select the date if you want more/less than a day's timeframe for deciding to count new views.
回答2:
Check if the IP address exist in the table within a time frame, if it does then don't enter it, just update the time. This is something for which you cant calculate the exact number, just an approximate count.
来源:https://stackoverflow.com/questions/6407395/knowing-user-refresh-the-page-web-stats