views:

51

answers:

2

Hello,

I am building a website in which the user can select what list items they see in their navigation menu, my idea is to store the menu items that the user selects in a cookie as this will stop the need for the user to be registered member on the website, is it possible to store realtime data in a cookie and how would I do this? For more information the navigation options are built from a mysql result, the then clicks a link and that link is added to a different list, if they click it again it is deleted, I need to add/remove these items from the cookie as the user add/removes it from there list.

+2  A: 

i would use the cookie only to identify the user and do all of your menu option saving in MySql.

Grab the user id from the cookie and query the db for the menu_options and display them.

Either way, storing the data in a cookie or in the database, when the cookie expires, so does (effectively) the user. Plus people delete cookies all the time using cleaners like Adware and CCleaner. I do this about once a week. Cookie = Gone.

mmundiff
+1. There's a maximum size for cookies (I think around 4kB), and sending them up and down for each request is inefficient. Much better keep that data where it's both generated and used, i.e. server-side, and only put a unique ID in the cookie for identification of the user.
Wim
A: 

This is a bad idea.

The number of cookies a browser can store is not defined (however there is a hard limit for most browsers). RFC 2109 suggests at least 20 cookies per host and a min cookie size of 4k. Certainly the latter is adhered to by most browsers.

You're also going to have to replicate all the features of session management without the nicety of having server-side state. You do not want the kind of pain going down this route will cause you. Keep your session data server-side.

There is no requirement for a user to 'log-in' to have a session. You just need to assign them an automatic identity in a persistent cookie (the replace that if they ever do sign in). And map the session back to a more long term storage when the user changes the config.

C.

symcbean