序列化的PHP对象不通过POST传递。

时间:2014-06-09 13:40:19

标签: php object post serialization

     $citation = new Citation();
                    $citation->user_id  =   $result['pmid'];
                    $citation->pmid      =  $result['volume'];
                    $citation->volume    =  $result['volume'];      
                    $citation->issue     =  $result['issue'];       
                    $citation->year      =  $result['year'];        
                    $citation->month     =  $result['month'];           
                    $citation->pages     =  $result['pages'];           
                    $citation->issn      =  $result['issn'];        
                    $citation->journal       =  $result['journal'];     
                    $citation->journalabbrev =  $result['journalabbrev'];   
                    $citation->title          = $result['title'];

                    $string_data = serialize($citation);

HTML

   <input type="checkbox" name="citation" value="<?php echo $string_data; ?>">

在POST =

之前输出$ string_data

○:8:&#34;引文&#34;:16:{S:7:&#34; USER_ID&#34 ;; S:7:&#34; 8046837&#34 ;; S:4: #34; PMID&#34 ;; S:2:&#34; 52&#34 ;; S:6:&#34;体积&#34 ;; S:2:&#34; 52&#34 ;; S:5 :&#34;问题&#34 ;; S:1:&#34; 6&#34 ;; S:4:&#34;年&#34 ;; S:4:&#34; 1994&#34 ;;小号:5:&#34;一个月&#34 ;; S:3:&#34;君&#34 ;; S:5:&#34;页面&#34 ;; S:6:&#34; 1535-8&# 34 ;; S:4:&#34; ISSN&#34 ;; S:9:&#34; 0047-1852&#34 ;; S:7:&#34;期刊&#34 ;; S:51:&# 34; Nihon rinsho。日本临床医学杂志&#34;; s:13:&#34; journalabbrev&#34 ;; s:13:&#34; Nippon Rinsho&#34;; s:5:&#34; title&#34 ;; s :46:&#34; [结节病的支气管镜分类]。&#34 ;; s:8:&#34;摘要&#34 ;; N; s:11:&#34;从属关系&#34 ;; N; s :7:&#34;作者&#34 ;; N; S:9:&#34;条款ArticleID&#34 ;; N; S:8:&#34;关键字&#34 ;; N;}

并且可以被反序列化....

                    $new = unserialize($string_data);

                    print_r($new);

给......

引用对象([user_id] =&gt; 8046837 [pmid] =&gt; 52 [volume] =&gt; 52 [issue] =&gt; 6 [year] =&gt; 1994 [month] =&gt; Jun [pages ] =&gt; 1535-8 [issn] =&gt; 0047-1852 [journal] =&gt; Nihon rinsho。日本临床医学杂志[journalabbrev] =&gt; Nippon Rinsho [title] =&gt; [结节病的支气管镜分类] 。[abstract] =&gt; [affiliation] =&gt; [authors] =&gt; [articleid] =&gt; [keywords] =&gt;)

但是当我使用复选框发布到另一个页面,然后

    echo $_POST['citation'];

我得到了

数组([0] =&gt; O:8:)

我搜索了Stack以获得解决方案以及PHP文档但没有成功。 POST操作是否以某种方式改变了序列化数据?

2 个答案:

答案 0 :(得分:0)

我认为你应该使用json_encode和json_decode函数

答案 1 :(得分:0)

问题解决了。

第一:

      $string_data = serialize($citation);

      $string_data = base64_encode($string_data);

然后使用POST发送$ string_data

然后

      $new_object = unserialize(base64_decode($citation));

另一方面......