Home > Article > Backend Development > PHP implements session multi-domain name and multi-server sharing session_id_PHP tutorial
We can save the sessionid in the database to achieve this. This method is relatively safe and widely used, but it is not the scope of our discussion. Below we will only talk about simple
First generate a sessionid during verification;
代码如下 | 复制代码 |
Session_start(); $sessionId = session_id();//得到sessionid //将session下发给客户端 ......... ?> |
The client carries the sessionid variable to request data
代码如下 | 复制代码 |
Session_id(‘$sessionid’);//注意这个时候session_id()这个函数是带有参数的 Session_start();//这个函数必须在session_id()之后 ?> |
The problem of multi-server sharing session, everyone should be able to understand this, when a website If the number of users is too large, a server cluster will be used, for example, a dedicated server for login. After the user logs in through the login server, the login server saves the user's login information session, and other accessed servers, such as the movie server, do not have this session, so we have to share this session through a unique identifier of the session