开发者

knowing user refresh the page, web stats

开发者 https://www.devze.com 2023-03-14 13:06 出处:网络
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 ?

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, p开发者_高级运维age, referrer", "'$sid', '$ip', '$time', '$page', '$referrer'");
    }
}

thanks :)

Regards, Stecy


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消