簡體   English   中英

如何從數據庫反序列化codeigniter會話數據

[英]How to unserialize codeigniter session 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;

我嘗試了反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框架中有效。

對於外部腳本,您可能需要仔細看看。 變量之間用“;”分隔 和“ |” 然后進行序列化,因此這可能有效(未經測試):

$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"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM