unserialize() [function.unserialize]: Error at offset ecshop 原因是字符串太大了。

来源:互联网 发布:微信企业号 php源码 编辑:程序博客网 时间:2024/05/16 19:42
/** * 读结果缓存文件 * * @params  string  $cache_name * * @return  array   $data */function read_static_cache($cache_name){    if ((DEBUG_MODE & 2) == 2)    {        return false;    }    static $result = array();    if (!empty($result[$cache_name]))    {        return $result[$cache_name];    }    $cache_file_path = ROOT_PATH . '/temp/static_caches/' . $cache_name . '.php';    if (file_exists($cache_file_path))    {        include_once($cache_file_path);        $result[$cache_name] = $data;        return $result[$cache_name];    }    else    {        return false;    }}/** * 写结果缓存文件 * * @params  string  $cache_name * @params  string  $caches * * @return */function write_static_cache($cache_name, $caches){    if ((DEBUG_MODE & 2) == 2)    {        return false;    }    $cache_file_path = ROOT_PATH . '/temp/static_caches/' . $cache_name . '.php';    $content = "<?php\r\n";    $content .= "\$data = " . var_export($caches, true) . ";\r\n";    $content .= "?>";    file_put_contents($cache_file_path, $content, LOCK_EX);}




Notice: unserialize() [function.unserialize]: Error at offset解决方法

offset,Notice,unserialize, function, Error
报错信息:
Notice: unserialize() [function.unserialize]: Error at offset 159 of 647 bytes in \eshop\includes\lib_common.php on line224

lib_common.php的224行
  1. $cfg = unserialize($GLOBALS['_CFG']['integrate_config']);
复制代码


是将会员整合配置信息反序列化的操作,产生报错的原因是因为序列化的字符串格式不对,无法正常反序列化,产生这种情况的时候很少,目前只在UTF-8编码格式下发现。

解决方法,在lib_common.php大约604行找到
  1.         if (empty($arr['integrate_code']))
  2.         {
  3.             $arr['integrate_code'] = 'ecshop'; // 默认的会员整合插件为 ecshop
  4.         }
  5.         write_static_cache('shop_config', $arr);
复制代码


修改为
  1.         if (empty($arr['integrate_code']))
  2.         {
  3.             $arr['integrate_code'] = 'ecshop'; // 默认的会员整合插件为 ecshop
  4.         }
  5.         if (!empty($arr['integrate_config']) && EC_CHARSET == 'utf-8')
  6.         {
  7.             $arr['integrate_config'] = preg_replace('!s:(\d+):"(.*?)";!se',"'s:'.strlen('$2').':\"$2\";'",str_replace(' ','',$arr['integrate_config']));
  8.         }
  9.         write_static_cache('shop_config', $arr);
复制代码


修改完成后,进入后台清除缓存。

注意:这个只能用在lib_common.php 224行的这个错误上,如果不是请不要随便修改程序。如果在使用中遇到问题可通过站内信与我联系。

0 0
原创粉丝点击