Keeping tracks of ratings, multiple values in cookie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
arpowers
Forum Commoner
Posts: 76
Joined: Sun Oct 14, 2007 10:05 pm
Location: san diego, ca

Keeping tracks of ratings, multiple values in cookie

Post 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...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Keeping tracks of ratings, multiple values in cookie

Post 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.
(#10850)
User avatar
arpowers
Forum Commoner
Posts: 76
Joined: Sun Oct 14, 2007 10:05 pm
Location: san diego, ca

Re: Keeping tracks of ratings, multiple values in cookie

Post by arpowers »

I know.. I'm keeping track of the votes in the db as well... the cookies are mostly for immediate feedback...
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: Keeping tracks of ratings, multiple values in cookie

Post 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);
 
User avatar
arpowers
Forum Commoner
Posts: 76
Joined: Sun Oct 14, 2007 10:05 pm
Location: san diego, ca

Re: Keeping tracks of ratings, multiple values in cookie

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Keeping tracks of ratings, multiple values in cookie

Post 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.
(#10850)
Post Reply