douping1581
2013-06-13 05:14
浏览 59
已采纳

如何从解密的字符串中读取数据[关闭]

string(284) "a:4:{s:10:"session_id";s:32:"01a046827a00cf838a1b3ce585cc82fb";s:10:"ip_address";s:13:"124.43.56.156";s:10:"user_agent";s:120:"Mozilla/5.0 (Windows; U; Windows NT 6.2; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27";s:13:"last_activity";i:1371099813;}"

This is a decrypted cookie from CodeIgniter. I need to access data from this. Preferably convert to an array or something which is easily accessible like data -> session_id. Which would be the possible way to extract data from this?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dscrb00804 2013-06-13 05:16
    已采纳

    Just unserialize it.

    var_dump( unserialize('a:4:{s:10:"session_id";s:32:"01a046827a00cf838a1b3ce585cc82fb";s:10:"ip_address";s:13:"124.43.56.156";s:10:"user_agent";s:120:"Mozilla/5.0 (Windows; U; Windows NT 6.2; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27";s:13:"last_activity";i:1371099813;}'));
    
    点赞 评论
  • doupu7651 2013-06-13 05:17

    That's a serialized string, just call unserialize

    $array = unserialize($string);
    

    and you have it back as array:

    Array
    (
        [session_id] => 01a046827a00cf838a1b3ce585cc82fb
        [ip_address] => 124.43.56.156
        [user_agent] => Mozilla/5.0 (Windows; U; Windows NT 6.2; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27
        [last_activity] => 1371099813
    )
    
    点赞 评论
  • dongmeng2687 2013-06-13 05:18

    I think its a serialized array. Use unserialize and get it to variable.

    $arr = unserialize($str);
    
    点赞 评论
  • doushitang4276 2013-06-13 05:25

    Use unserialize to convert the serialize string into array

       $arr = unserialize($string);
    
       print_r($arr) //will display you the array values
    
    点赞 评论

相关推荐 更多相似问题