Tracking unique visitors only?

后端 未结 7 1900
猫巷女王i
猫巷女王i 2020-12-03 05:49

Currently I have a file called \"hits.php\" and on any page I want to track page hits I just use

How can I track u

7条回答
  •  清歌不尽
    2020-12-03 06:17

    I found the solution of very poor quality and just a quick and dirty way of doing it.

    I too was developing something similar and formulated a quick method which works without redundancy.

    I needed a counter for every time someone accessed another user's profile.

    Pseudo:

    • Create a table with viewer's name and viewee's name (daily_views table).
    • Check to see if exists the viewer's name with the viewee's name (on the same row).
    • If they do not exist, update user counter +1 (in users table).
    • Else do nothing.
    • Reset entire table values null every 24/12 hours via cron job.

    This will deny the same person accessing the same user profile to add 1 to the counter on refresh for the whole day (or 12 hours) whereas the above solution by Glenn Nelson would indeed add 1 to the counter, but deny adding to every user's counter at the same time.

    Not only this, but if you were to logoff and log back in to the website, then it would simply re-add to the counter in which some cases trolls and haxorz wannabe's will exploit this (as the session is destroyed and started again).

    Here are my sample tables:

    users 
    {
    user_id INT(8) auto increment, user_name varchar(32), user_counter INT(12)
    };
    daily_views
    {
    view_id INT(8) auto increment, viewer_name VARCHAR(32), viewee_name VARCHAR(32)
    };
    

    Here is sample code I've written:

    
    

提交回复
热议问题