Scenario No 1
On page1.php I use php with MySQL to get a product’s data to the page. When a user wants to proceed to page, 2 he clicks on a button.
On page2.php there is also some info about the product, mainly for checkout purposes. For this data to be displayed I make use of the ID of the product so page2.php is actually page2.php?id=123. Therefore, using again PHP and MySQL I get the data I need.
Scenario No 2
On page1.php I use php with MySQL to get a product’s data to the page. The needed values for page2.php are stored in sessions. When a user wants to proceed to page 2, he clicks on a button.
On page2.php now, the information about the product is shown using sessions. This time page2.php is actually page2.php that it is shown on the address bar.
I prefer doing this with scenario 1. The user will be able to copy/paste or send through a button the page to a friend for direct access. I don’t think that one more hit to the db is a problem.
What is your opinion ?
I would agree that scenario 1 is better. You should use a session for its intended purpose, carrying state of a particular user, not misuse it as some form of caching mechanims in my opinion.
That’s why you use the database in the first place – to have efficient access to your data. Why try to build a cache around the thing that should actually improve the efficiency if used?
If access ever becomes a bottleneck and you really need to look into caching, then there are still better mechanisms than to use your session for this purpose.