unserialize用法

unserialize

(PHP 3 >= 3.0.5, PHP 4, PHP 5)

unserialize --  从已存储的表示中创建 PHP 的值

描述

mixed unserialize ( string str [, string callback] )

unserialize() 对单一的已序列化的变量进行操作,将其转换回 PHP 的值。返回的是转换之后的值,可为 integerfloatstringarrayobject。如果传递的字符串不可解序列化,则返回 FALSE



function check()
  {   
    if(isset($_COOKIE[$this->auth])){
                dump($_COOKIE);
      $u = unserialize($_COOKIE[$this->auth]);
      dump($u);exit;
      if(md5(SEED.$u['id'].$u['level']== $u['seed'])){
        return $u;
      }
    }
    return array('id'=>0,'level'=>0);
  }



结果:

array (size=1)
  'auth' =>  'a:5:{s:2:"id";s:1:"1";s:5:"level";s:2:"20";s:4:"name";s:7:"siyecao";s:5:"email";s:19:"[email protected]";s:4:"seed";s:32:"16480b70119339e1cdbf4f51b7e90078";}' (length=159)
array (size=5)
  'id' =>  '1' (length=1)
  'level' =>  '20' (length=2)
  'name' =>  'siyecao' (length=7)
  'email' =>  '[email protected]' (length=19)
  'seed' =>  '16480b70119339e1cdbf4f51b7e90078' (length=32)

你可能感兴趣的:(php笔记)