I am managing my category variables using php session.
If a user clicks like this:
- index
- category (category sets a session variable)
- product (product fetches that variable)
After, if the user, instead of pressing the home link (which refreshes the index page), presses the browser’s back button this happens:
- the user just reached the index page with the category variable set earlier;
- if he clicks on a product directly from the index, the old category is getting displayed.
Basically,
Is there a way to set new session variables when a user hits the browsers back button (and the page is not refreshed)?
And this is exactly why you should keep requests self contained. All the information you need to build your navigation should somehow be present in the request itself, meaning in the URL. Either you can deduce the category from the product the user is looking at or some other information already contained in the request, or you should transport the selected category in a query parameter (
...?cat=42). This way each request expresses all the necessary information within itself and will not screw up any separate state saved elsewhere.