Home > Mobile >  Can I keep a session when leaving the page (and return later)?
Can I keep a session when leaving the page (and return later)?

Time:03-17

For reasons out of my control I need to send form data to an other server and return back right away after it has been processed and alter the state of an entry in my local data base when returning.

In principle it works fine but when I return it seems my session has been terminated and I need to login again in order to reach the page I want to reach. Unfortunately, this hinders my script to actually inform my data base that the external data base has processed the data. Of course I could open up the page for public access but I want to avoid that. An other option would be to send a key with the form data and to only bypass the need for a login if the returned key is correct.

But is there a way of telling my session to only terminate after a certain time instead of when leaving the page? (Of course I want to keep the possibility to deliberately terminate the session on logout.)

I just realised that the problem seems to occur on Firefox on Windows and on Mac but not on my GNU/Linux system. There I stay logged in when leaving and returning to the web page. This is the reason why at first I didn't know that people could have this problem.

CodePudding user response:

I found out that also creating a session on the external page ended the original session (at least in Firefox on Windows and on OSX). After removing the session_start() on the external page the session stays alive as intended. It seems there can be only one active session in any given tab and creating a new session terminates the old one. (However, this termination only happens on Windows and OSX but not on Firefox ESR GNU/Linux.)

It is strange that the default setting for session cookies is to be deleted if a new session is started (if not on Firefox ESR on GNU/Linux).

What ever the true explanation is: this is the behaviour I discovered.

  • Related