How to track a users last visited page?

As far I’ve researched there are two ways in my mind to achieve this and they are-

  1. Database: Save the value of the current page ID in the database for the user and continuously update it. That way you can get the last visited page by a user. You can store multiple page visit stat as serialized data in database. Though it is kinda performance reducer but it’s effective. And it saves the data which you can use later for any kinda query.
  2. Session: You can also use session to store the previous page ID and this way you can get the last visited page. At session destruction you can get the data by session_set_save_handler

Hope those above ways are gonna help you.