What does this error means "unserialize() [<a href='function.unserialize'>..."?

Started by ddabcd277, January 02, 2012, 02:09:09 PM

Previous topic - Next topic

ddabcd277

Hello,

What does this error means:
Quote8: unserialize() [<a href='function.unserialize'>function.unserialize</a>]: Error at offset 61 of 91 bytes
File: /home/www/myforum.com/www/Sources/Load.php
Line: 1237

I have plenty of this error in the log!!! Is it dangerous? How to fix it?

Marry X'mas and Happny new 2012!

kat


ddabcd277

Here you have. Nothing is changed nothing is modified at all.

kat

Nothing wrong, there.

Can you either go to Admin>Forum maintenance and "Empy file cache", or find the "cache" directory, using FTP, and emptying-out the contents?

ddabcd277

Thanks K@. I delete the cache directory using an FTP server and also performed "Empy file cache" from Admin>Forum maintenance as you suggested. Unfortunately, still this error appears in the error log. I have thousands of this error a day. Have a feeling that this error appears every time someone browse a topic. Over the error it is given a link to a topic where it had appeared. I just don't have luck with my forum.  :(

feline

Make the follow database query in phpMyadmin or what you have and post the result:

SELECT * FROM smf_settings where variable = 'displayFields'

ddabcd277

Sorry, I didn't answer immediate. I am not familiar with phpmyadmin...Here what I have as a result from the SQL tab when put this value:

Value:
Quote
a:1:{i:0;a:3:{s:1:"c";s:8:"cust_492";s:1:"f";s:10:"Устройство";s:1:"b";s:1:"0";}}

Is that what you need?

Thanks,

kat

You may be on the right track. :)

To clarify:

Go to phpmyadmin and click on the "MYSQL" tab.

A new window'll open with "Run SQL query/queries on server "localhost":" or similar.

In the left pane, click on your database name

Then, in the big box, type:

SELECT * FROM smf_settings where variable = 'displayFields'

and you'll see the results, above the box.

feline

Quote from: ddabcd277 on January 04, 2012, 04:08:12 PM
a:1:{i:0;a:3:{s:1:"c";s:8:"cust_492";s:1:"f";s:10:"Устройство";s:1:"b";s:1:"0";}}
Well .. that seems like a utf8 - iso problem ..
the array (normaly) looks as:
array(
   0 => array(
      'c' => 'cust_492',
      'f' => 'Устройство',
      'b' => 0,
   ),
)
but .. the serialized string of 'f' => 'Устройство' have not the correct lenght ...
the serialized array must be hold:
a:1:{i:0;a:3:{s:1:"c";s:8:"cust_492";s:1:"f";s:20:"Устройство";s:1:"b";s:1:"0";}}
now the unserialized array returns the correct result.

So the question is ... you use utf8 on your forum?

ddabcd277

Thanks for the reply! Very good logic.  :)

QuoteSo the question is ... you use utf8 on your forum?
Well, I think so...  :-\

Here two images from the admin panel:




Is there other place where UTF8 should be set?

BTW maybe this information will be of some help. I am not sure. From months I was running SMF 2.0 (never having this error) but recently I began having many emails from people not managing to register at my forum. (don't know what I did wrong) So I was advice to overwrite the smf files ones more. And...briefly...I did that. Seems everything is ok now except this strange error which began appearing in the error log which I have in thousand error logs a day. 

Cheers,

feline

Quote from: ddabcd277 on January 04, 2012, 06:35:21 PM
QuoteSo the question is ... you use utf8 on your forum?
Is there other place where UTF8 should be set?
Yes .. the database .. please look at the file Settings.php in the forum root folder.
In this file you must find:
$db_character_set = 'utf8';

ddabcd277

Yes, in the Settings.php it is set to utf8. I have attached the Settings.php file.

Illori

it is not a good idea to attach your settings.php file with your username and password to your database in it. i have removed it from your post.


feline

Well .. i looked into the depth .. PHP 4 and 5 do not have built-in Unicode support, so it can give problems with serialized utf8 strings. But .. it's possible to fix that.

Look at follow code example:
$data = 'a:1:{i:0;a:3:{s:1:"c";s:8:"cust_492";s:1:"f";s:10:"Устройство";s:1:"b";s:1:"0";}}';
echo 'original: '. $data .'<br />';
echo 'unserialized: ';
var_export(unserialize($data));
echo '<br />';

// correct the utf8 strlen
$data = preg_replace('/s:\d+:"([^"]*)";/e', "'s:'. strlen('\\1') .':\"\\1\";'", $data);

echo 'modified: '. $data .'<br />';
echo 'unserialized: ';
var_export(unserialize($data));


The result is follow:
original: a:1:{i:0;a:3:{s:1:"c";s:8:"cust_492";s:1:"f";s:10:"Устройство";s:1:"b";s:1:"0";}}
unserialized: false
modified: a:1:{i:0;a:3:{s:1:"c";s:8:"cust_492";s:1:"f";s:20:"Устройство";s:1:"b";s:1:"0";}}
unserialized: array ( 0 => array ( 'c' => 'cust_492', 'f' => 'Устройство', 'b' => '0', ), )


So you can fix the serialized data with the simple code lines:
// unserialize with suppress E_NOTIFY and success test
function unserialize_utf8($data)
{
$tmp = @unserialize($data);
if($tmp === false)
$tmp = unserialize(preg_replace('/s:\d+:"([^"]*)";/e', "'s:'. strlen('\\1') .':\"\\1\";'", $data));
return $tmp;
}

ddabcd277

Hi feline,

I really very appreciate your attitude for this issue. Many thanks.  :)

So...excuse me I am not very good at php. So where to put this lines? In which file?

Cheers,

feline

Open your Load.php in a editor (like notepad++) and find around line 1232:

// Are we also loading the members custom fields into context?
if ($display_custom_fields && !empty($modSettings['displayFields']))
{
$memberContext[$user]['custom_fields'] = array();
if (!isset($context['display_fields']))
$context['display_fields'] = unserialize($modSettings['displayFields']);


Replace this with:

// Are we also loading the members custom fields into context?
if ($display_custom_fields && !empty($modSettings['displayFields']))
{
$memberContext[$user]['custom_fields'] = array();
if (!isset($context['display_fields']))
{
$context['display_fields'] = @unserialize($modSettings['displayFields']);
if($context['display_fields'] === false)
$context['display_fields'] = unserialize(preg_replace('/s:\d+:"([^"]*)";/e', "'s:'. strlen('\\1') .':\"\\1\";'", $modSettings['displayFields']));
}


Save and test again ...

ddabcd277

Ok, I did your suggestion in Load.php. I have also cleared the error log in the forum (more than 6000 errors approximately for two days). Lets see now what will happen. Will inform you tomorrow is the same error appearing again in the error log.

Thanks,


ddabcd277

A big Thank you to feline! :) After I put the code in Load.php no more the irritating error in the error log till now! Issue solved! Thank you very much for your help.  :)

Advertisement: