How to safely edit the PHP Guestbook Data File

More
16 years 7 months ago #885 by Pete
We have been getting questions regarding editing the PHP Guestbook Data File, which unfortunatly is NOT as simple as it may seem.

The problem is that whenever people manuall edit the data file they automatically make the character count that the PHP Engine automatically puts in the data file off.

For Example, take a look at the following example data file line:
Code:
O:7:"gbClass":4:{s:6:"gbDate";s:19:"Thu 02/14/08 9:21AM";s:6:"gbFrom";s:4:"Pete";s:7:"gbEmail";s:14:"email@mail.com";s:9:"gbMessage";s:4:"Test";}<!-- E -->

This consists of the following parts:
Code:
// PHP Object from the Class "gbClass" O:7:"gbClass":4:{ // string variable named "gbDate", length 6 s:6:"gbDate"; // string value for gbDate value, with length 19 s:19:"Thu 02/14/08 9:21AM"; // string variable named "gbFrom", length 6 s:6:"gbFrom"; // string value for gbFrom, length 4 s:4:"Pete"; // string variable named "gbEmail", length 7 s:7:"gbEmail"; // string value for gbEmail, Null value N; // string variable named "gbMessage", length 9 s:9:"gbMessage"; // string value for variable gbMessage, length 4 s:4:"Test"; // End of gbClass Object } // Message Entry Seperator between objects <!-- E -->

The problem is that whenever someone edits the data file manually, they throw the character count for the value off. So unless they manually count the new character count length and edit the length manually, it corrupts the data file.

In the above example, lets say I wanted to change the "gbMessage" from "Test" to "Testing Guestbook". You would have to:
Code:
before: s:4:"Test"; after: s:17:"Testing Guestbook"

So the number 4 representing length of the gbMessage value before will have to be changed to the number 17 which is the new length of the guestbook. Another problem with manual editing of entries, is that the users automatically introduce New Line characters "\n" in PHP, in the middle of the guestbook data file in several locations (because of "word wrap" in their editors. This also corrupts the data file.

For DigiOz Guestbook version 1.8.0 (in development), we are going to change this system to an XML based data file which doesn't serialize the PHP object for storage. In the meantime, manual inspection of the data file should solve this problem.

Thanks,
Pete

DigiOz Webmaster
www.digioz.com

Please Log in or Create an account to join the conversation.

Time to create page: 0.117 seconds
Powered by Kunena Forum