EchoFool Posted October 2, 2011 Share Posted October 2, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/248301-unserialize-error/ Share on other sites More sharing options...
mikesta707 Posted October 2, 2011 Share Posted October 2, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/248301-unserialize-error/#findComment-1275052 Share on other sites More sharing options...
EchoFool Posted October 2, 2011 Author Share Posted October 2, 2011 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/248301-unserialize-error/#findComment-1275054 Share on other sites More sharing options...
mikesta707 Posted October 2, 2011 Share Posted October 2, 2011 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 = ""; Quote Link to comment https://forums.phpfreaks.com/topic/248301-unserialize-error/#findComment-1275057 Share on other sites More sharing options...
EchoFool Posted October 2, 2011 Author Share Posted October 2, 2011 Thanks - that seems to have solved the issue Quote Link to comment https://forums.phpfreaks.com/topic/248301-unserialize-error/#findComment-1275059 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.