2
I have a system from which I need the session to be active due to an internal tool, but some users are leaving the system by directly closing the browser, without clicking the button Come out system, where the session is terminated. Is there any way the session is terminated if the user closes the system directly by the browser?
The session is created after the user logs in:
$_SESSION["Logado"] = true;
And when you click the exit button, I destroy the session:
session_destroy();
So far all right, but if the user closes the browser? My initial reasoning was to create a time session when logging in:
$_SESSION["TempoAtivo"] = time() + 360;
But I don’t know what to do from here. I accept suggestions in jquery, javascript and PHP.
One solution is to use cookies, so you can set the cookie’s expiration time
– Renato Junior
Check out this OS reply: https://stackoverflow.com/a/24402832/4734177
– gustavox
I haven’t tried it, but maybe it works if you do an Ajax by calling a. php that destroys the session after closing the page with the function
$(window).unload(function() { ajax });
.– Sam
You can do as the friend above reported to destroir when close the browser. Maaas if the browser crashes or forces its shutdown unexpectedly the function does not perform. After I started using cookies I never wanted to know
$_SESSION
for login. I only use cookies, I store in the bank the key that is in the cookies with the expiration time both in the bank and in the browser. And I renew key time every time the user changes page.– Willian Coqueiro
Take a look at this later. https://stackoverflow.com/questions/8311320/how-to-change-the-session-timeout-in-php
– PauloHDSousa