Check server-side response (session validity/isset)
Check server-side response (session validity/isset)
I saw another thread about this but it had no answer.
Im using php sessions server-side to grant / deny users access to certain fields.
Problem occurs when the user has been inactive for some time (24mins i think session lifetime), come back to do a table search which will result in a "invalid json response" due to the session variables not set in server-side script.
On other pages I do a header location redirect to login page, and I would like to do the same in this case.
I was thinking I could check server side for active session and if not then return a 0 / false or whatever, return that to client and if so do a window.location redirect.
But how can I check this in client side before datables tries to render the table?
Answers
You could make a synchronous ajax call to check - or a promise.
I found this in my code somewhere ...
I could do that, but then I need to execute that with every search/edit?
Just seems a bit unnecessary instead of checking valid sessions server side which is done anyway, and send back a false response
Have the server return valid JSON such as:
And listen for
xhr
which will check for thesessionExpired
and perform whatever action you need (reload to a login page for example).Allan
Yes, I found another thread dealing with the same issue which was solved with xhr event.
This is my solution
in PHP
And on client