我想在外部脚本中使用CI会话,并从数据库中获得了以下数据。
__ci_last_regenerate|i:1446535049;ci_UserID|s:1:"2";ci_UserName|s:24:"example@xyz.com";logged_in|b:1;
我试过unserialize
和unserialize(base64_decode($data))
,但都失败了。
请帮助提取此数据。
我在这里得到了解决方案
所以我使用了会话解码
session_decode('__ci_last_regenerate|i:1446535049;ci_UserID|s:1:"2";ci_UserName|s:24:"example@xyz.com";logged_in|b:1;');
因此会话解码将所有加密数据存储在正常的php会话中。
我可以使用echo $_SESSION['ci_UserID'];
访问
伙计们,谢谢你们的帮助
如果这是一个会话变量,您可以使用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
对不起,我只是在发布了代码之后才阅读了"外部脚本"。这显然只适用于CI框架。
对于外部脚本,您可能需要仔细查看。变量由";"answers"|"分隔,然后序列化,因此这可能有效(未测试):
$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"