Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

PHP serialize() unserialize()



Recommended Posts

  • PHP serialize()函数

    PHP 可用的函数PHP 可用的函数 serialize() 函数用于序列化对象或数组,并返回一个字符串。

    serialize() 函数序列化对象后,可以很方便的将它传递给其他需要它的地方,且其类型和结构不会改变。

    如果想要将已序列化的字符串变回 PHP 的值,可使用 unserialize()。

    string serialize ( mixed $value )


    • $value: 要序列化的对象或数组。




    PHP unserialize()函数

    unserialize() 函数用于将通过 serialize() 函数序列化后的对象或数组进行反序列化,并返回原始的对象结构。

    当使用 serialize() 函数将对象序列化后,可以将这个得到的字符串保存到文件或者数据库中,

    然后在需要的地方使用 unserialize() 函数将这个字符串反序列化,unserialize() 函数的语法格式如下:

    mixed unserialize ( string $str )


    • $str: 序列化后的字符串。


    返回的是转换之后的值,可为 integer、float、string、array 或 object。

    如果传递的字符串不可解序列化,则返回 FALSE,并产生一个 E_NOTICE。




    PHP serialize()和unserialize()注意事项


    // to safely serialize
    $save_in_db = base64_encode(serialize($value));
    // to unserialize value fetched from db...
    $value = unserialize(base64_decode($fetched_from_db));


    function my_serialize( $obj ) 
       return base64_encode(gzcompress(serialize($obj))); 
    function my_unserialize($txt) 
       return unserialize(gzuncompress(base64_decode($txt))); 
Link to post
Link to comment
Share on other sites


discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    • Create New...