tags:

views:

172

answers:

4

On my non membership site I would might like to keep track of what songs a user last listened to via Cookies

The maximum number of values in this cookie would be maybe 100 values. The IDs of the songs: (30,31,32,32,34....... and on and on.)

Is there any reason not to do this?

Users are not authenticated in anyway.

And this is non essential just for their benefit.

I am mostly concerned with it potentially affecting page performance.

+2  A: 

If you want use it to show only for the user, I don't see why not. It will only increase the bandwidth sent from the user to the server.

But if you want to see what you users are listening, I recommend you use a database instead, sending to the user only a hash for an table on database. Like this:

userid int(11)
hash string(26)
song string(100)

Then, just send the hash parameter to user, and get all the song from database.

Nathan
No. Its just for their benefit. So they can see what songs they have already listened to. It's not really essential in any way just helpful to them.
ian
It will work if you don't want to show then what they listened their entire "life" on site. Since its a cookie, they will be gone when the user clean it or their lifetime ends. But to show then what they "just" listened, this is a good choice. :)
Nathan
Yes will have basically a 2 week life and I will make it so it only contains about 100 values at any time.
ian
A: 

I would think that doing it via database keeps all of the data on your end. You can still show them what the last 100 songs they listened to would be. If you are requiring them to be authenticated to view the last 100 songs, then I'd say it makes more sense just to keep the data on the database (reduces bandwidth etc).

Polaris878
But its definitely not authenticated so it seems simple to keep it on their side?
ian
+1  A: 

How important is it that the data be retained? Cookies aren't guaranteed to be presented during the next session; the user might have their browser configured to discard cookies upon close or silently ignore cookies from non-whitelisted domains. The cookie might also expire naturally between the user's visits to your web site.

To my mind, cookies are a poor choice as the primary store for any important piece of data. I think you'd be better off storing the information in a database; it should be a cheap enough query to pull it back out when needed, and as Nathan points out, the information remains visible to you in a form that's convenient for any data mining, reporting or comparison operations you might wish to perform.

Rob
It's not really important at all. It's just for their benefit.And its not authenticated so do you think a non authenticated DB store of the information would be more likely to be present than cookies?Most of my users will just be average users who don't delete their cookies or block cookies or that type of thing.
ian
If the users don't are authenticated, there is no reason to use a database, since you'll need a cookie on the user's browser to keep track of the data.
Nathan
I think Rob's point was that using cookies exclusively would prohibit him from having access to the data for his own statistical purposes.
Tom
A: 

Seems ok. Just be sure to filter/whitelist what you get from the cookie.

koen
why is that? It won't used for a query or anything. Is it still necessary?
ian
If your not using it for a query it's not necessary. I assumed the songs would be in a database and you would retrieve them from the id's stored in the cookies.
koen
Actually that was not a good answer. Filtering input is always good and might prevent unforeseen errors.
koen