Welcome Guest, Not a member yet? Register   Sign In
How much is too much session data?
#8

(07-08-2017, 02:21 AM)PaulD Wrote:
(07-07-2017, 05:18 PM)skunkbad Wrote: I try to put as little as possible in the session. In most cases, all I have is an authentication identifier. Everything else is in the database, so why store it in the session? Yes, yes, there are obviously reasons to have things that persist between page loads, but for those I mostly use cookies. I like to keep the session clean. That's just my preference.

For instance, suppose I am not logged in, and I add an item to my basket. Where does that information go? I have no user id to associate the item with the user, so I have to add it to the session. If they then log in, I transfer the basket to an order table that is linked to the user.

Another example might be that the visitor clicks the 'collapse menu' option. Again, that setting has to go into the session does it not, so on the next page load the menu will load up in a collapsed state.

Another example might be a product comparison. A non-logged in visitor adds two items to the comparison list or a favourites list. This info needs to be in the session data. Or the selection of dark text/ light background or light text/dark background layouts etc. All those UI choices need to be in the session surely?

I did for a while have two columns in my tables, user_id and session_id, so that a non logged in user had a user_id of 0. But the tables filled up with junk data so fast that I really felt uncomfortable with it. It seemed messy. At the same time, having to use either table data or session data depending on the user status, also becomes very messy.

Is there something I am missing? Or, because a user can be logged in and identified, or not, is there always going to be two parallel systems running, one based on user_id and the other based on session_id.

I do like the idea of keeping session data clean, but if I do not load up the session data with information, I find that the cost of doing this is very messy functions. If I use session data for logged in users as well as visitors, everything suddenly feels cleaner. So the choice seems to be messy session data or messy functions.

Hmmm. Really not sure now.

Best wishes,

Paul


I did say that there were reasons to have things persist between page loads, and you've pointed out some examples.

I did say that I like to use cookies too.

I'll admit, I mostly work on one website, and 90% of it is not visible to the public. Out of:
  • 95 controllers
  • 65 models
  • 140 tables in the database
  • 42 libraries
I need to put nothing in the session except for my auth identifier. We are using about 5 cookies.

It's just my opinion that session data storage is overused by PHP beginners, and sometimes those habits are long lasting.
Reply


Messages In This Thread
How much is too much session data? - by PaulD - 07-07-2017, 09:32 AM
RE: How much is too much session data? - by PaulD - 07-07-2017, 12:08 PM
RE: How much is too much session data? - by PaulD - 07-08-2017, 02:21 AM
RE: How much is too much session data? - by skunkbad - 07-08-2017, 08:36 AM
RE: How much is too much session data? - by PaulD - 07-10-2017, 10:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB