Cause:
Two sites with the same program are deployed using the IP address and port access method in the LAN. It is found that after a user logs on to the same station, the user logs on to the other station at the same time, after one station exits, the other station also exits. After reading the program, we found that both sites use the session-only method to record the logon status. Only PHPSESSID data is stored in the Cookie, and the IP address and port format are used, we found that the Cookie scopes of the two websites are the same and all belong to the IP address of the server, which is the cause of this problem.
Solution:
/* --------------- The following is nonsense -----------------*/
1. Change the program to use the cookie record. Do the two sites use different pre-cookie suffixes? Forget it.
2. Because there is a DNS service on the server, bind two different domain names to the two sites, and then modify the DNS address for all users in the LAN? If I go to multiple computers, I can only change them one by one, which is not in line with our technology? Norm zookeeper! And it's still lazy... Forget it.
3. Add an IP address to the server and bind the two sites to different IP addresses. So many IP addresses in the Lan are idle. You can do the following: add an IP address to the NIC directly in the local connection, and a MAC address conflict will be prompted in different gateways. Since I do not know much about network construction, I want to add a virtual network card. Isn't it enough to assign an IP address to the virtual network card? There should be no problem with the two NICs and two MAC. I tried to find that the virtual things can only be used on this computer. Other computers cannot be pinged .. Although it was later found that the server has two physical NICs, but the second Nic is not plugged in and has no permission to plug in the IDC .. Forget it.
4. Finally, it is implemented through the program...
/* --------------- The above is nonsense -----------------*/
Add a php code to the common file of the program or other public files as follows:
Ini_set ('session. Name', 'phpsessid _ RS ');
Of course, the second parameter is the name used when the session is saved to the cookie. You can set your favorite name...
This is because the session names used by all programs are in php. PHPSESSID is the default name set in ini. Therefore, if a session is used between websites in the same domain (with different IP addresses), a shared conflict may occur. Now the two sets of programs use different session. name to save the sessionid, so there will be no session conflicts.
Solve the problem!
PS: Male. My keyboard has two broken keys .. Q: Why does the keyboard fail to respond when some keys are pressed? Even in the security mode PE system, this phenomenon will develop, the column where the key is located will not respond, and the next column will be developed .. The last step is to abandon the keyboard and directly use the virtual desktop keyboard...
Additional article: java solution
Multiple tomcat or weblogic ports are set up on one server, and the session is lost when access is started. For example, services A and B. After you log on to A in A browser and access service B on the open browser, the session is lost when you click access, you must log on to A again. After searching the data, the problem was found because the IP address is the same as the domain, and B's set-cookie command was received to overwrite the corresponding cookie content, including jsessionid, the session of A is lost. If the IP address is different, this problem will not occur. The cookie corresponding to the two sessions with the same IP address is the same, but unfortunately the sessionID is saved in the cookie. In this way, when accessing A and then accessing B, the sessionid of B overwrites the sessionid of. This problem cannot be solved, so you should avoid two ports, preferably two IP addresses. It turns out to be a disaster caused by cookies. It does not differentiate ports, resulting in the frequent overwriting of multiple sites, resulting in session loss.
Solution:
Method 1: deploy different application services on different virtual hosts or map different IP addresses.
Method 2: corresponding to tomcat service processing method: modify the coocie name to ensure that the cookie is not duplicated, that is, the jsessionid is not duplicated, so that the sessioncookiename domain name is different under the same ip address.
1. tomcat5 modification method
Add the org. apache. catalina. SESSION_COOKIE_NAME parameter to the startup item.
Linux
JAVA_OPTS = '-Dorg. apache. catalina. SESSION_COOKIE_NAME = yousessionname'
Win
Set JAVA_OPTS = "-Dorg. apache. catalina. SESSION_COOKIE_NAME = yousessionname"
2. Tomcat 6 and Tomcat 7 are modified in the same way.
The added parameter of tomcat takes effect for all the Context, which has a great impact. Therefore, you can only set the parameter for the Context in a later version.
Add the sessionCookieName parameter to the Context container label.
<Context path = "/" docBase = "webapp" reloadable = "false" sessionCookieName = "yoursessionname"> </Context>
3. weblogic modification method
Set different cookie-names for each application.
Weblogic settings (set different cookie-name ):
Add the following code in WEB-INFWeblogic.xml
<Session-descriptor>
<Cookie-name> JSESSIONID1 </cookie-name>
</Session-descriptor>