如何从数据库中反序列化codeigniter会话数据

时间:2022-10-06 13:35:27

I wan to use CI session in a external script and I got following data from database.

我想在外部脚本中使用CI会话,我从数据库中获取了以下数据。

 __ci_last_regenerate|i:1446535049;ci_UserID|s:1:"2";ci_UserName|s:24:"example@xyz.com";logged_in|b:1;

I have tried unserialize and unserialize(base64_decode($data)) but I am fail yet.

我尝试过反序列化和反序列化(base64_decode($ data))但我还是失败了。

Please help to extract this data.

请帮助提取这些数据。

2 个解决方案

#1


1  

I got the solution here

我在这里得到了解决方案

So I have used session decode

所以我使用了会话解码

session_decode('__ci_last_regenerate|i:1446535049;ci_UserID|s:1:"2";ci_UserName|s:24:"example@xyz.com";logged_in|b:1;');

So session decode stored all the encrypted data in normal php session.

因此会话解码在正常的php会话中存储了所有加密数据。

Which I can access using: echo $_SESSION['ci_UserID'];

我可以使用:echo $ _SESSION ['ci_UserID'];

Well guys thanks for the help

好的,谢谢你的帮助

#2


0  

If this is a session variable, you can use CodeIgniter's own session library. Consider the following code (in a controller):

如果这是一个会话变量,您可以使用CodeIgniter自己的会话库。考虑以下代码(在控制器中):

$this->load->library('session');                // load the session library
$session_data = $this->session->all_userdata(); // get all session data
print_r($session_data);                         // print and get the corrresponding variable name, e.g. "item"
$var = $this->session->userdata('item');        // pick one that suits your needs, e.g. item

Sorry, I have read "the external script" only after having posted the code. This obviously only works in the CI framework.

对不起,我在发布代码后才看到“外部脚本”。这显然只适用于CI框架。

For an external script you may need to have a closer look. The variables are separated by ";" and "|" and then serialized, so this might work (not tested):

对于外部脚本,您可能需要仔细查看。变量用“;”分隔和“|”然后序列化,所以这可能工作(未测试):

$row = explode(';', '__ci_last_regenerate|i:1446535049;ci_UserID|s:1:"2";ci_UserName|s:24:"example@xyz.com";logged_in|b:1;'); // load the database row
$userid = explode('|', $row[1]);
$userid = unserialize($userid[1]); // now $userid holds the value "2"

#1


1  

I got the solution here

我在这里得到了解决方案

So I have used session decode

所以我使用了会话解码

session_decode('__ci_last_regenerate|i:1446535049;ci_UserID|s:1:"2";ci_UserName|s:24:"example@xyz.com";logged_in|b:1;');

So session decode stored all the encrypted data in normal php session.

因此会话解码在正常的php会话中存储了所有加密数据。

Which I can access using: echo $_SESSION['ci_UserID'];

我可以使用:echo $ _SESSION ['ci_UserID'];

Well guys thanks for the help

好的,谢谢你的帮助

#2


0  

If this is a session variable, you can use CodeIgniter's own session library. Consider the following code (in a controller):

如果这是一个会话变量,您可以使用CodeIgniter自己的会话库。考虑以下代码(在控制器中):

$this->load->library('session');                // load the session library
$session_data = $this->session->all_userdata(); // get all session data
print_r($session_data);                         // print and get the corrresponding variable name, e.g. "item"
$var = $this->session->userdata('item');        // pick one that suits your needs, e.g. item

Sorry, I have read "the external script" only after having posted the code. This obviously only works in the CI framework.

对不起,我在发布代码后才看到“外部脚本”。这显然只适用于CI框架。

For an external script you may need to have a closer look. The variables are separated by ";" and "|" and then serialized, so this might work (not tested):

对于外部脚本,您可能需要仔细查看。变量用“;”分隔和“|”然后序列化,所以这可能工作(未测试):

$row = explode(';', '__ci_last_regenerate|i:1446535049;ci_UserID|s:1:"2";ci_UserName|s:24:"example@xyz.com";logged_in|b:1;'); // load the database row
$userid = explode('|', $row[1]);
$userid = unserialize($userid[1]); // now $userid holds the value "2"