File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes need to manage sigle session for same user in differnt browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

need to manage sigle session for same user in differnt browser

Ramesh Kumar
Ranch Hand

Joined: Oct 29, 2008
Posts: 42
Hi All
i got the requirement like when the same user hits the URL and login from different browser , need to kill the previously opened one .
(ex) if i LogIn in IE , it will create one session . if i again login in another browser like firefox with same username/password, it will create another one ,
so now i want to kill the previously opened (IE's ) session .is it possible ??

Ramesh

SCJP,OCA
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1220
    
    1

Approach can be --

When the user logs in first, generate a some random sequence number for him, store it in his session, and in the database's table.
The database only stores one random sequence number for the user.
Whenever the user logs in again from different browser, check if request is from different browser and check whether random sequence number in the session matches with the one in the database.
If it matches then no action need to be performed.
If it does not matches, it is not from same browser (mean user has logged in again). destroy previous session and now create a new random sequence number for him, store it in his session, and upate random number in the database's table (replacing old random number)


code to find browser name from request



hope this explanation will be helpful to you

~ abhay
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 586
    
    3

How are you authenticating your users now? Are you using any framework?
Arun Chidam
Ranch Hand

Joined: May 08, 2006
Posts: 79
Abhay Agarwal wrote:Approach can be --

When the user logs in first, generate a some random sequence number for him, store it in his session, and in the database's table.
The database only stores one random sequence number for the user.
Whenever the user logs in again from different browser, check if request is from different browser and check whether random sequence number in the session matches with the one in the database.
If it matches then no action need to be performed.
If it does not matches, it is not from same browser (mean user has logged in again). destroy previous session and now create a new random sequence number for him, store it in his session, and upate random number in the database's table (replacing old random number)


code to find browser name from request



hope this explanation will be helpful to you

~ abhay


Hi abhey,

How does your approach differentiates the sessions if the request is from same browser...i mean when they try to log in from same browser??...does it close the existing session and re-open new one???

Hi Ramesh,
When you say to terminate the old sesion, what about the data in the current state, say if he is in middle of adding items to his shopping cart as per your request, it will not only terminate the old session but also removes any progress made by the user using that session....
My suggesstion will be to setup a flag(with current browser name) in a database as soon the user logged in, if the user tries to login again with same browser then he should be re-directed to the old session, if it is from different browser then, either request the user to close the existing session and login or create a new session and copy the records from the old session (if there are any temporary state associated with the old session) and then invalidate the old sesion.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need to manage sigle session for same user in differnt browser