?
Solved

Deleteting browser session when closing TABs

Posted on 2009-04-17
10
Medium Priority
?
448 Views
Last Modified: 2012-05-06
I need to delete session variables when my users close the browser TAB in which they are working (I have non technical users that do not perform logout nor close the browser when they finish browsing my website in a shared PC after having had access with their own username and password, but just close the TAB in which they are working, so that the next user will be able to surf the site with username and password of the previous user). How can I do that in a way that works for all (or at least IE 7, FIreFox 2, FireFox 3) browsers?

I read somewhere that this problem cannot be solved in any way if the browser has a popup blocker setup. Is this true?
0
Comment
Question by:Esanteva
  • 5
  • 4
10 Comments
 
LVL 17

Expert Comment

by:Chris Harte
ID: 24167156
You cannot end a session using tab close, unless somebody has implemented it in the last year.
What you can do is record activity with a custom session handler and if there has been no activity for ten minutes, log them out.
0
 
LVL 19

Expert Comment

by:Michael701
ID: 24182073
Here's a thought, use getenv("HTTP_REFERER") at the top of all pages (probably where you also see if they are logged in). If it doesn't exist or isn't your domain, force a login.
0
 

Author Comment

by:Esanteva
ID: 24267854
> If it doesn't exist or isn't your domain, force a login.

Do you mean forse a logout?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Accepted Solution

by:
Michael701 earned 1500 total points
ID: 24270768
how about I say "force a re-login"

if getenv("HTTP_REFERER") isn't set or is'nt your domain, then it means

that they clicked on a link from another website

that they opened a new tab and used a favorites link to come to your site

that they opened a new tab and typed your site's url in the address bar

for all of these  it would be the first time to your site, so, make them login
0
 

Author Comment

by:Esanteva
ID: 24293173
> for all of these  it would be the first time to your site, so, make them login

Almost. Several users (e.g. me) are used to open several TABs to the website and they do this by opening a new TAB then retyping the URL or using their Favorites. Would the check on getenv("HTTP_REFERER") work also in this situation?
0
 
LVL 19

Expert Comment

by:Michael701
ID: 24294482
"opening a new TAB then retyping the URL or using their Favorites"

this would cause them to have to login again.

If you have a page open you could right click any link and 'open in new tab', this will not force them to login again
0
 

Author Comment

by:Esanteva
ID: 24306372
> If you have a page open you could right click any link and 'open in new tab', this will not force them to login again

Yes, this is clear. I'm only trying to understand if there is a way that would allow me to delete the session variables when there are no more TABs open on the website without having to force a change of habits (mine and my users')
0
 

Author Comment

by:Esanteva
ID: 24382611
Sorry for having waited so long before coming back to this question of mine. I was thinking if I could detect when a TAB is closed by using something like

<body onbeforeunload="closeSession();">  

and then in the closeSession function I could do some server side work by using AJAX? What do you think? Could that solve the problem?
0
 
LVL 19

Expert Comment

by:Michael701
ID: 24390440
This issue there is that if they have 2 tabs open then it will end the session when the first tab is closed.
0
 

Author Comment

by:Esanteva
ID: 24410020
I see. Thanks.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month16 days, 14 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question