Home >Backend Development >PHP Tutorial >PHP operates sessions of multiple users and multiple threads (login status session value automatically updated)

PHP operates sessions of multiple users and multiple threads (login status session value automatically updated)

WBOY
WBOYOriginal
2016-07-25 08:57:211257browse
This article introduces how PHP operates sessions of multiple users and multiple threads to automatically update the session value of the user's login status. Friends in need can refer to it.

The implementation code for automatically updating session status is as follows:

<?php
//保存当前session id;
$my_session_id = $_COOKIE[session_name()]; 

session_start();
.......//一些操作,比如验证当前用户是否有权限操作session更新

{//此处可以循环以操作多个其他用户的session

session_write_close ();
session_id($_refresh_user_sessoin_id); //$_refresh_user_sessoin_id 是想要更新的其它用户的session的id;
//用 session_id()函数不带参数即可取得当前用户的sessionid,但需要在session-start()之后,否则用$_COOKIE[session_name()];
session_start();
.....//对要操作的session进行操作.

}//循环处理结束

session_write_close ();
session_id($my_session_id);//还原当前用户的session
session_start();
?>

First, save the sessionid of the person you want to refresh.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn