Php session problems and multiple tabs

dear everyone i have a big problem while using session and clicking right click open in new tab

consider this problem

In step 1 i select  a product i am storing $_SESSION['product_id'] = 55;
step 2 i go to other products with id = 88  and opens another product in a new tab.
Now moves to that tab It's now step 1 for the product2
Now $_SESSION['id'] is set 88
User moves tab 1 and continues to step 3
But now $_SESSION['id'] = 88   and not 55

How can i prevent this. This is a cooked up problem so would like a generalized solution.

If you are using cookies to store session ID (the most common scenario) then there’s no way to prevent this because that’s the nature of cookies that they are shared among all open windows and tabs that contain the same web site. If you want separate sets of data to persist across different tabs then you need to switch from cookies to some other mechanism. Some ideas:

  1. Pass the data you want to persist in the URL of the page. Or, you can create a separate session for each tab but then you have to pass session ID in the URL. For this you’ll have to dynamically create links on your page, of course.

  2. If you can tolerate to require javascript for this then you can use session storage - this way you can store separate sets of data in each tab.