knowing user refresh the page, web stats

蹲街弑〆低调 提交于 2019-12-24 19:28:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!