Message Boards

How to kill session when user goes to another page on the same tab

thumbnail
Marcos Ferreira, modified 7 Years ago.

How to kill session when user goes to another page on the same tab

New Member Post: 1 Join Date: 7/21/16 Recent Posts
Hello!

After a full day of unsuccessful internet search, please help me.

After the user logs in to the Portal then he accesses another page (on the same tab) when he returns to the portal page the session does not die. The user can access any page and return to the portal and the session is still alive. How to kill the session after the user accesses the other page on the same tab?
Is there any configuration in the portal-ext.properties file?

Regards,
Marcos
thumbnail
Olaf Kock, modified 7 Years ago.

RE: How to kill session when user goes to another page on the same tab

Liferay Legend Posts: 6396 Join Date: 9/23/08 Recent Posts
Marcos Ferreira:
After the user logs in to the Portal then he accesses another page (on the same tab) when he returns to the portal page the session does not die. The user can access any page and return to the portal and the session is still alive. How to kill the session after the user accesses the other page on the same tab?


Welcome to the web. A session is maintained by your application server. The only thing you could do is to shorten the session duration to a minute and implement some custom javascript polling while you still display a page. This would keep the session alive as long as it runs. As soon as someone leaves the page (on all tabs, because they all share the same session) the JS polling won't run any more and the session would time out in a minute.

No, there's no configuration for this in Liferay
thumbnail
David H Nebinger, modified 7 Years ago.

RE: How to kill session when user goes to another page on the same tab

Liferay Legend Posts: 14914 Join Date: 9/2/06 Recent Posts
And to add to Olaf's response, tabs are controlled by the browser and all browsers share cookie information, session tokens, etc. on all of the currently opened tabs.

The tabs are not considered separate browsers, they are the same browser.
thumbnail
Jaydip Lakhatariya, modified 7 Years ago.

RE: How to kill session when user goes to another page on the same tab

Junior Member Posts: 53 Join Date: 4/18/13 Recent Posts
Hi,

Here is the way through javascript you can achieve your requirement. Below is the event in javascript which use to detect when user moves out from the current tab. When this event triggers then you can send redirect to /c/portal/logout user which will kill the portal's session.

document.addEventListener('visibilitychange', function(){
    location.href="<%= themeDisplay.getURLSignOut()%>";
})


Hope this helps.

Regards,
Jaydip
thumbnail
Olaf Kock, modified 7 Years ago.

RE: How to kill session when user goes to another page on the same tab

Liferay Legend Posts: 6396 Join Date: 9/23/08 Recent Posts
Jaydip Lakhatariya:
Here is the way through javascript you can achieve your requirement. Below is the event in javascript which use to detect when user moves out from the current tab. When this event triggers then you can send redirect to /c/portal/logout user which will kill the portal's session.


That's a very effective way to annoy all those users that are opening multiple tabs. As soon as they change to a different tab, all of them will be logged out.