title: How can I authenticate a user session in Core PHP (on each page) and restrict the user to reload the page or go back
body: <p>I have created a page with login and logout facility in core PHP. When I login, the system starts a session and takes me to a new page where a unique key is passed in the URL which is nothing but the Primary Key of that particular user. But, when this key is changes, the user account is also changed easily without any authentication.</p>
  
  <p>For example: If user A log in to the system with its own credentials, he is successfully logged in. Let's say his primary key is 2. </p>
  
  <p>Thus he is taken to the following URL: <code>www.example.com/dashboard.php?id=2</code> Now, let's say that there is a user B with primary key 4 and if the user A manually changes the key the URL <code>www.example.com/dashboard.php?id=2</code> to <code>www.example.com/dashboard.php?id=4</code>, the session changes to user B. Thus, authenticity is not maintained.</p>
  
  <p>The system should be like if the key in URL is changes manually, or page is force reloaded or back button is pressed, then the session needs to be destroyed.</p>