Problem:
A friend of mine needed a way for his users to post comments to his website in response to his news posts. There’s a ton of ways to get this working, any blog software will do the trick. But there’s a catch, he doesn’t have access to a database. He’s been writing these news updates old-school, editing the html file every time he wants to post. Talk about dedication!
Solution:
I had to figure out a way to make comments work without a database. The easy answer was, have them email their comments and he could update the page himself. But who wants to do that? So I decided to store the comments in an XML file using php to update it whenever a user posted.
Rather than stopping at just comments, I decided to write a nice script for him to post his news from the site, and store the news posts in an XML file as well. This required a simple login system to keep the bad people out. And if you’re already talking XML, why not make them RSS capable for his users to subscribe to his site?
So here you go, my “FeatherNews” package. Requires PHP 5 to parse through the XML correctly but is very lightweight at only 5kb. There’s three files in the package:
- index.php - All the heavy lifting. Has all the functions for creating the settings file, creating the comments directory and XML, updating the news XML and parsing through the xml to output the news.
- comments.php - Parses through the comment XML files to show responses to posts. Also updates the xml when a new comment is posted.
- styles.css - Real basic styles, easy enough to modify for yourself
Hope you enjoy the code and can learn something from it. I would definitely suggest a full featured package like WordPress if you can swing the database, this isn’t very scalable. If all you need to do is set up a simple way to update a page though, this is a nice, lightweight solution.



Post a Comment