【问题标题】:unable to unserialize a string in php无法在php中反序列化字符串
【发布时间】:2012-02-01 09:32:37
【问题描述】:

谁能告诉我以下代码有什么问题?反序列化此字符串时,我得到布尔值 false:

a:3:{s:10:"Subscriber";O:14:"SubscriberType":8:{s:14:"organizationid";s:3:"omm";s:5:"jobid";s:13:"4f27d819d9fd2";s:8:"sequence";s:8:"42781971";s:20:"SubscriberTypedate";s:10:"2012-01-31";s:20:"SubscriberTypetime";s:8:"04:01:29";s:9:"timestamp";s:19:"2012-01-31T04:01:29";s:20:"SubscriberTypecert";s:46:"omm^4f27d819d9fd2^42781971^2012-01-31T04:01:29";s:11:"certificate";s:32:"ab673e29e0eb69a62b39781cdbec6368";}s:8:"Activity";O:12:"ActivityType":6:{s:5:"title";s:6:"ethics";s:8:"provider";s:21:"O'Melveny & Myers LLP";s:6:"format";s:2:"11";s:10:"completion";s:10:"2012-01-12";s:11:"description";s:35:"some's : test description here";s:7:"credits";s:17:"some credits here";}s:4:"Code";s:8:"SMH10634";}

我正在使用以下代码来序列化数据:

$stype = new SubscriberType($data1['OrgID'],$data1['OrgKey']);
$atype = new ActivityType($rdata['Title'],$data1['Provider'],$rdata['Format'],$rdata['Completion'],$rdata['Description'],$rdata['Credits']);
$repData = htmlentities(serialize(array("Subscriber"=>$stype,"Activity"=>$atype,"Code"=>$data2['ClientCode'])),ENT_QUOTES);
$sql = "insert into table values(compress('$repData'))";

以及下面的代码来反序列化它。

$sql = "select uncompress(RepData) as RData from table";
$rData = unserialize(html_entity_decode($data['RData']));

【问题讨论】:

  • 你用来反序列化的代码是什么?

标签: php serialization


【解决方案1】:

我希望你只使用serialize() 和unserialize()。

当我运行它时,我收到Error at offset 169 of 700 bytes。您应该编码特殊字符并转义引号。方法如下 -> http://davidsword.ca/unserialize-error-at-offset/

【讨论】:

  • 刚刚解决了这个问题,我没有使用htmlentities和html_entity_decode函数,而是使用了addslashes和stripslashes函数。
  • 您的链接已过期,您可以在答案中添加说明吗?
  • 哇那是很久以前的事了...但我认为在使用serialize()之前应该使用htmlspecialchars()和addeslashes()进行清理
猜你喜欢
  • 2018-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-26
  • 1970-01-01
  • 1970-01-01
  • 2021-02-26
相关资源
最近更新 更多