User Options - DB or Cookies?
Moderator: General Moderators
User Options - DB or Cookies?
A client has asked me to store user options that remain set between accesses. For example, if a tab on the sidebar is open, he wants it to stay open the next time the user comes to the site. What's the most efficient way of doing this, storing it with cookies or in the database? I'm guessing cookies, but I just want to make sure. Thanks.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: User Options - DB or Cookies?
1. Database requires user to login to restore state.
2. Cookies are a decent bet for storing application GUI state
Cookies eventually expire, database is perpetual. Cookies are specific to a machine, which can be benfitial and a hinderence.
The choice is complicated and depends on you and your clients needs, etc.
Cheers,
Alex
2. Cookies are a decent bet for storing application GUI state
Cookies eventually expire, database is perpetual. Cookies are specific to a machine, which can be benfitial and a hinderence.
The choice is complicated and depends on you and your clients needs, etc.
Cheers,
Alex
Re: User Options - DB or Cookies?
Cookie to store user/session identifier and nothing more, all else in the DB.
Re: User Options - DB or Cookies?
Would there be any noticeable difference in performance if, say, every time a user closes a tab, I run an AJAX update of the database to reflect this option, rather than if I just set/update a cookie?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: User Options - DB or Cookies?
Most likely no. However, it is highly dependent on your server hardware, server software/configuration, and available resources.jraede wrote:Would there be any noticeable difference in performance if, say, every time a user closes a tab, I run an AJAX update of the database to reflect this option, rather than if I just set/update a cookie?
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: User Options - DB or Cookies?
I would personally, rather store GUI positions, dimensions, etc in a cookie, strictly for the speed. Everytime someone resizes a listview column header, resizes a window, repositions a object, etc. It's just easier to stuff that in a cookie, not to mention there is no backend code required to make this work, so the same code can be applied on a application built in PHP or ASP or JSP, etc.Cookie to store user/session identifier and nothing more, all else in the DB.
Other than that, I would almost always side with sessions.
Cheers,
Alex
Re: User Options - DB or Cookies?
Depends on how persistent you want something to be. If you were to want those GUI options to be (more) permanently persisted, then it would have to be server side, and if you wanted those settings to be offered to the user no matter which user agent/terminal they login from, then it would also have to be server side. 
Re: User Options - DB or Cookies?
Cookies are more appealing at the moment because there's no back-end scripting involved. I don't think a user would get mad if a tab is minimized when he logs in on a different computer. But I'm interested to see how much an application would get weighed down with a big number of these options and an AJAX call to update the database with each click. With a small number, I don't think there would be much of a difference.
Re: User Options - DB or Cookies?
I'd be more worried about the stability/persistence of cookies before worrying about server load. 
Besides which, cookies are sent across the wire with every request, and are processed by your web-server with every request. $_COOKIE is populated every request, etc. Just because a value is in a cookie, does not mean it is not sent over the wire.
Besides which, cookies are sent across the wire with every request, and are processed by your web-server with every request. $_COOKIE is populated every request, etc. Just because a value is in a cookie, does not mean it is not sent over the wire.
-
cpetercarter
- Forum Contributor
- Posts: 474
- Joined: Sat Jul 25, 2009 2:00 am
Re: User Options - DB or Cookies?
The big advantage of using a database is security. However, there isn't - I think - a security issue here. You simply want to retrieve information about open tabs etc. So go with cookies. You can set them in Javascript if you like eg add to the bits of JS which open/close your tabs. Easy.