Chrome Toggle different devices view destroys the session Chrome Toggle different devices view destroys the session google-chrome google-chrome

Chrome Toggle different devices view destroys the session


Finally and after several hours of reviewing my code and debugging every single thing I came up with a solution to my problem :

  • my hypothesis in the question that the devices are independentfrom each other is quite correct because every device has a differentHTTP_USER_AGENT

You can try it like this :

echo $_SERVER['HTTP_USER_AGENT'];

Toggle different devices on the browser and see the result .

So as for sessions best practice based on stack overflow and many other resources it is a good practice to save $_SERVER['HTTP_USER_AGENT'] in a session and later on check the session after login which means the logged in user is exactly the user coming from that browser

And that's what i was doing i was checking for the user login session and the user agent session

And that's what was causing the problem so when i toggle different devices the HTTP_USER_AGENT gets changed so the session doesn't match and therefore i get logged out automatically.