Skip to main content
Known Participant
April 2, 2012
Question

where to store location variable

  • April 2, 2012
  • 1 reply
  • 1729 views

I have an intranet application that will be used by many users.  Each user has one or many locations.  The data is dispayed by location, so the user selects which location they are working with from a drop down in the header.  Once they select their location, the can begin viewing and updating the data.  I store the location in a session variable and use it in all my queries to select only that particular location, or to only insert or update that location.  Is the session variable the right thing to use here?  I am concerned because the user can leave the computer while filling out a form and come back in an hour or so, and the session variable will have timed out.  I cannot default it to anything and they will get an error.  Any deas of a better way to store the location?

This topic has been closed for replies.

1 reply

davidsimms
Inspiring
April 3, 2012

Store location in a cookie.

Known Participant
April 4, 2012

I will look into using cookies.  The only issue with cookies is that a user can disable them in their browser, and the core functionality will be unavailable.  I also do NOT have a session timeout set.  I cannot think of what else to do that would be better and for the life of me cannot think of why storing this in a session is a bad idea.  I am trying to get ahead of any issues that may arise.  How does the session timeout work?  Does the session get refreshed when the user uses the session variable and the timeout gets restrted?  Or, does it go away no mater what 30 mins after it gets created?

12Robots
Participating Frequently
April 4, 2012

There is nothing wrong with storing it in a session if you are OK with prompting them for the value again if they let their session timeout.

Getting errors is, of course, not acceptable. You need to write your application so that before it tries to use the session value it checks for its existence. If it does not exist, then redirect the user to a page where they can select it again.

If you are not OK with prompting them for the value again, then you'll have to do somethign else, like set a cookie. If they have cookies disabled you will need to warn them that the application will not work with cookies disabled. Of course, sessions won't work with cookies disabled either. Frankly, I think users with cookies disabled are stupid and they are probably use to havign 80% of the internet not work for them.

There are no perfect solutions in a stateless environemnt like the web. You are not going to find a better solution than storing it in a session variable or in a cookie.

jason