Codeigniter 3通过ID获取特定的会话数据 [英] Codeigniter 3 get a specific session data by id
本文介绍了Codeigniter 3通过ID获取特定的会话数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Codeigniter 3会话表如下所示
Codeigniter 3 session table looks like the following
CREATE TABLE IF NOT EXISTS `ci_sessions` (
`id` varchar(40) NOT NULL,
`ip_address` varchar(45) NOT NULL,
`timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
`data` blob NOT NULL,
KEY `ci_sessions_timestamp` (`timestamp`)
);
我可以通过
$this->session
但是如果我愿意想访问特定的会话,我该怎么做。
But If I'd like to access a specific session how would I do that.
我可以像这样
$this->db->where('id', 'db256c0b82f8b6ba1e857d807ea613792817157a');
$res = $this->db->get('ci_sessions');
echo $res->row()->data;
我得到以下内容
__ci_last_regenerate|i:1450694483;email|s:18:"amzadfof@gmail.com";user_code|s:7:"AAA1787";loginInId|i:8;users_id|s:11:"00000000002";active|s:1:"1";username|s:13:"amzadmojumder";fname|s:5:"Amzad";lname|s:8:"Mojumder";phone|s:11:"07900642131";title|s:1:"#";created_on|s:19:"2015-12-17 16:31:56";last_login|s:19:"0000-00-00 00:00:00";in_group|s:15:"2,1,3,4,5,6,7,8";
如何将其转换为php对象或数组?我试图
How could I convert this to an php object or array? I have tried to
unserialize($res->row()->data);
也尝试过
session_decode($res->row()->data);
这些都不起作用。任何帮助将不胜感激。
none of this worked. Any help will be appreciated.
推荐答案
老问题,是的,但这对我有用。
Old question, yeah but this worked for me.
https://github.com/wikimedia/php-session-serializer
从数据库中获取会话数据后,我就做了
After fetching the session data from database, I just did
$array = PhpSessionSerializer::decode($session);
这篇关于Codeigniter 3通过ID获取特定的会话数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文