Home>Article>Backend Development> How to restore session content through session_id in php

How to restore session content through session_id in php

little bottle
little bottle forward
2019-04-22 14:00:44 4498browse

This article mainly talks about restoring session content through session_id, which has certain reference value. Interested friends can learn about it.

1. Obtain session_id

// 开启session session_start(); // 取得 $_SESSION['test'] = '111222333'; $session_id = session_id(); echo $session_id;exit; // fu1dmdnrk0o2pi612b8jh9kts1

2. Obtain session through session_id

// 根据session_id查询session信息 session_id('fu1dmdnrk0o2pi612b8jh9kts1'); session_start(); print_r($_SESSION);exit; // Array ( [test] => 111222333 )

One issue that needs attention here is:When obtaining session_id, you need to first session_start(); When obtaining the session through session_id, session_start() is required.Because session_start() will check whether there is currently an active session, if not, create a session and access it through the $_SESSION array. If the session already exists, the session_start() function will load the registered session variables so that they can be used.

Related tutorials:PHP video tutorial

php Chinese website learning topic:php session(Including pictures, texts, videos, cases)

The above is the detailed content of How to restore session content through session_id in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete