Java does not allow different IP addresses of the same account to log on to the system at the same time. solution compatible with IE Firefox

Source: Internet
Author: User

The requirement is that the same account cannot log on to the system at the same time. If one account is online, other users cannot use this account.


The function is very simple and the process is quite tangled.



This article solves the problem of simultaneously logging on to the same user with different IP addresses in IE and Firefox browsers, including the case that the browser is not properly closed.


Let's talk about the solution process. I thought it would be better to use session access. Later, I could only use the tag window in the same browser. Cross-browser approach won't work. Because sessionId is different. (It has nothing to do with sessionID)


I found some solutions online. Some listeners are used as the write method, and the database adds fields to determine the status. .... It's useless... Now I think it is too complicated and completely unnecessary.


The database field cannot be changed because the power is disconnected. As for closing the window "X" instead of selecting the "exit" button, this function can be controlled through JS. Easy to solve.


Implementation Method: add the static variable map array to the action to store the login user information. First, determine whether there is a record of the user information. If this user information exists, the login will not be allowed, not added to map. That's simple.


The second difficulty is that the browser selects the "X" button instead of the exit button. You need to add JS on the page to assist in clearing the session cache and map data information in the background; trigger the exit method to clear the session information and the user information in the Map.

(There are three types of local browsers: chrome/ie/firefox; ie/firefox has solved the "X" function of closing the window; chrome has not found a solution, the problem with chrome is that after the user logs in, he first executes the following js to clear the session information in the background and then logs in again. This is also true for ie at the beginning. Later, the IE browser was added to solve the problem. If you have read this article, give me some advice ).



$ (Window). bind ('beforeunload', function (){

Var isIE =/msid/I. test (navigator. userAgent )&&! Window. opera;

If (isIE ){

Var n = window. event. screenX-window. screenLeft;

Var B = n> document.doc umentElement. scrollWidth-20;

If (window. event. clientX> 360 & window. event. clientY <0 | window. event. altKey ){

// Close the event


$. Ajax ({

Url: "exitLogin. action", // background action, clear session data

Type: "post ",

Success: function (){

Alert ("You have logged out ");

}

});


} Else {

// Is a refresh event

}

} Else {// firefox


$. Ajax ({

Url: "exitLogin. action", // background action, clear session data

Type: "post ",

Success: function (){

Alert ("You have logged out ");

}

});

}


});


The map is not cleared because the session times out. When you log on, you must first go to map to batch the information, so that you cannot log on. So add a timer on the page. Periodically clear the data in the map.






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.