Hello Monks

I'm looking for any advise on doing something which is pretty much impossible to guarantee (and also a subject that has been beaten to death, so sorry for bring it up again).

We have a custom "forums type" application where we want to try to track the truly unique page views per person/machine as we plan to give incentives to those that are the most popular/most viewed.

Right now I'm planning on starting with just IP's and cookies (will probably be looking at flash shared objects soon).

I'm interested in anyone's opinions on a better approach then what I'm currently doing and also if anyone has any ideas on how to best deal with cookie size.

The plan so far is this

1. Have a table created that stores a page view, the table will have the message id, IP address, date viewed and a user id (if the person is logged in).

for example:

create table Views ( id int(11), UserId int(11), IPAddress varchar(15), DateAdded timestamp default current_timestamp )
Then when viewing a page I would start with
if ($session_data->{'LoggedIn'}) { $existing_view = $db->selectall_arrayref(qq|Select DateAdded from +Views where Id = ? and (IPAddress = ? or UserId = ?)|,undef,($id,$r-> +connection->remote_ip,$userid)); } else { $existing_view = $db->selectall_arrayref(qq|Select DateAdded from +Views where Id = ? and IPAddress = ?|,undef,($id,$r->connection->remo +te_ip)); }
From there the plan would be
unless (@$existing_view) { # get our cookie of id's if ($cookie) { unless ( grep { $_ == $id } @cookieids ) { if ($user_session_data->{'LoggedIn'} == 1) { $db->do(qq|Insert into Views (thread_id,IPAddress,UserId) values ( +?,?,?)|,undef,($id,$r->connection->remote_ip,$userid)); } else { $db->do(qq|Insert into Views (thread_id,IPAddress) values (?,?)|,u +ndef,($id,$r->connection->remote_ip)); } $cookie = $existing_cookie . $new_cookie; } else { $cookie = $id; } # set the new cookie
That is about it, I know this code isn't copy/paste/run but its more to explain the flow then test anything. Like I said, I'd like to hear if anyone has any issues to the approach and/or if anyone has any comments on the cookie.

Right now what bothers me most about the above is there is no real limit to the size of the cookie as it could kept getting added to forever, which means at some point it will be too big.

TIA for any help!


In reply to Another page view tracking question by Analog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.