Page 1 of 1

Keeping tracks of ratings, multiple values in cookie

Posted: Sun Jan 27, 2008 9:02 pm
by arpowers
Hey everyone,

I'm working on a project where there is a rating system.

Every time a user votes I would like to store this in a cookie and check against this if the user tries to vote again (see youtube's system)

My question is how to store or log multiple datapoints into a single cookie?

Youtube seems to store info from all rated video's into one cookie titled something like "ratings list"...

how is this done? My guess is something to do with serialization...

Re: Keeping tracks of ratings, multiple values in cookie

Posted: Sun Jan 27, 2008 9:27 pm
by Christopher
Users can easily delete cookies. If you wanted to do better validation you would probably check it IP address, browser string, etc. to identify unique users. You cannot guarantee that is cannot be circumvented, but you can make it reasonable accurate.

Re: Keeping tracks of ratings, multiple values in cookie

Posted: Sun Jan 27, 2008 10:56 pm
by arpowers
I know.. I'm keeping track of the votes in the db as well... the cookies are mostly for immediate feedback...

Re: Keeping tracks of ratings, multiple values in cookie

Posted: Sun Jan 27, 2008 11:45 pm
by JAM
Agree with arborint. There is no 'safe' way except if you are using some kind of login system, where you can track these events connected ti user id's or similiar. Another topic tho.

You were on the right track tho, serialize() and perhaps base_64encode() or de other various encoding functions, would be interesting to read up on;

Code: Select all

 
 $array[] = 'foo';
 $array[] = 'bar';
 echo $cookiedata = serialize($array);
 $newarray = unserialize($cookiedata);
 print_r($newarray);
 

Re: Keeping tracks of ratings, multiple values in cookie

Posted: Sun Feb 03, 2008 11:33 pm
by arpowers
thats the thing... our users will be logged in...

if--in that case, where you're logged in--- you don't need to track with cookies, why does youtube do it?

Re: Keeping tracks of ratings, multiple values in cookie

Posted: Mon Feb 04, 2008 12:19 am
by Christopher
You don't know that YouTube "tracks" with cookies. They have a cookie. It can be used for many reasons, often for redundancy.