[英]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))
但是我還是失敗了。
請幫助提取這些數據。
如果這是一個會話變量,則可以使用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.