ian
ian

Reputation: 12335

efficency of storing data in cookies

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.

Upvotes: 0

Views: 598

Answers (4)

koen
koen

Reputation: 13757

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

Upvotes: 0

Rob
Rob

Reputation: 48369

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.

Upvotes: 1

DigitalZebra
DigitalZebra

Reputation: 41553

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).

Upvotes: 0

Nathan
Nathan

Reputation: 4067

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.

Upvotes: 2

Related Questions