Jump to content

Unserialize error


EchoFool

Recommended Posts

Hey

 

 

I got this script which is trying to unserialize  but i get this error and have no idea what it means so i equally have no idea how to fix the problem.

 

 

This is what it says:

 

 

Notice: unserialize() Error at offset 0 of 4 bytes

 

 

 

 

This is the line which causes the error:

 

 

<?php
$contents = unserialize(file_get_contents($this->msgsFile));
?>

 

Does any one know what the error means? And what i need to look for to fix it.

Link to comment
https://forums.phpfreaks.com/topic/248301-unserialize-error/
Share on other sites

The unserialize function takes a string representation of a PHP variable (generally created by its sister function, serialize). You seem to be passing in the contents of a file rather than a serialized string. What are you trying to accomplish here?

Link to comment
https://forums.phpfreaks.com/topic/248301-unserialize-error/#findComment-1275052
Share on other sites

Well the script i bought from a website for my live chat feature..

 

Its in a function called load messages, which says:

 

# loadMessages function

# Loads the messages based on the specified output

 

So my guess here is that the line trying to get messages from my message.txt file ? But currently as no one has spoken yet, the message.txt is empty - would that be the likely cause of the problem ?

Link to comment
https://forums.phpfreaks.com/topic/248301-unserialize-error/#findComment-1275054
Share on other sites

Well I have no clue how your script works (although using unserialize like that doesn't sit well with me.) It may be because the string is empty, as that is the notice that PHP issues when unserialize encounters and non-unserializable string IIRC. But I don't really know the context that that line is in, nor do I know what the format of the text file will be. You can check if the file is not empty before you do the unserialize, IE

$txt = file_get_contents($this->msgsFile);
if (!empty($txt))
     $contents = unserialize($txt);
else
     $contents = "";

Link to comment
https://forums.phpfreaks.com/topic/248301-unserialize-error/#findComment-1275057
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.