Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.