Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

johnw65's avatar

Track Multiple Sessions for an User

I have an application in which you can select a fiscal year and division. However, if an user log in again on another browser tab , I want them to view record for a different fiscal year/division.

So I've tried saving sessionid, fiscal year, division, and user to a table for that particular login. However, the sessionid changes at each request. What is the best way to track user, fiscal year and division information for each login. Thank you.

0 likes
4 replies
martinbean's avatar

@johnw65 I don’t really know what the problem is you’re trying to solve? If a user is picking a fiscal year and division to filter some resource, then that should have its own URL (either different path, or query string parameters). That way you don’t need to do this weird session tracking stuff. The user just sees what they’ve requested in that tab.

johnw65's avatar

@martinbean

Appreciate your fast response. Let me clarify.

When an user first login, the user selects 2021 for fiscal year and division = 'first'. So now user can view all fiscal year and division information.

However, my client want the same user to login in again, and view fiscal year 2020 and division='second' information on another tab

I tried tracking using session variables, however, once in a while the session key gets lost. So I'm trying to use a table to track fiscal year, division, user, and unique id. I tried using sessionid but for each refresh, the session id changes. Should I generate a unique token? What is the best way to handle this?

martinbean's avatar
Level 80

@johnw65 What are you trying to save to the session though if a user’s just picking a completely different fiscal year in a new tab?

There is no issue here. This is how web pages work. Each request is stateless.

  • User logs in on Tab A and selects a fiscal year and division. URL is updated (i.e. query string added: ?fiscal_year=2020&division=ABC) and shown results for that fiscal year and division.
  • User logs in on another tab, they’d just do the same: select a fiscal year and division, URL is updated and they’re shown results for fiscal year and division they selected in that tab.

I don’t understand what you want in the session if a user is wanting to view two different result sets in two different tabs?

johnw65's avatar

@martinbean I understand your solution, so obviously I'm not explaining it clearly.

We have a main menu where the user selects the fiscal year and the division. From this fiscal year and division, they can view many reports and many different forms. However, sometimes, an user wants to open up a different fiscal year and division and compare the report or data entry form. So they can open up to 8 different fiscal year and division information via a separate login. So I need to be able to somehow save the information for up to 8 different logins for a user with the appropriate fiscal year and division rather than passing fiscal year and division. So basically, they have a default fiscal year and division for each login.

Please or to participate in this conversation.