Session Sharing Issues and Solutions

Source: Internet
Author: User

Server
The server is shared by website a and website B. The URLs for accessing A and B are http: // server/a, respectively,

Http: // server/B. When you access site A and site B from client C at the same time, the same session will be assigned.

Id. If it is a coincidence that the session of Site A and the session of Site B use a variable of the same name, it will produce a big problem.
The cause is in the default settings of PHP. ini:
; The path for which the cookie is valid.
Session. cookie_path =/
; The domain for which the cookie is valid.
Session. cookie_domain =
; Whether to use cookies.
Session. use_cookies = 1

C
When you access a for the first time, the site will allocate a sessionid in the cookie. This cookie will be carried every time C accesses.
Session
ID of the session to be processed. If you use the default settings in PHP. ini, the cookie carried by C is valid in the range of http: // server. When C
This cookie will also be carried when B is accessed, and B will see that there is a session in the cookie
The session is read, and the session is the session assigned to C by site B.

One way to solve this problem is to set your own independent parameters when writing code. For example:
Ini_set ('session. cookie_path ', dirname ($ _ server ['script _ name']);
Ini_set ('session. name', 'mysessionname ');

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.