Simple-as-pi PHP blog without a database - The WWW

Users browsing this thread: 1 Guest(s)
hades
Long time nixers
If you've ever wondered how easy it'd be to make your own blog without a database, let me assure you that it's pretty simple.

But it's stupid. If your blog suddenly gets popular, constantly opening and closing and reading from text files will stress out your server a lot more than reading from a single database would. That, and for the most part, if you're using a free host, they keep your databases on something with decent I/O like an SSD, while keeping your server root on a larger, but slower drive (Mainly because Databases need to be fast, and don't take up as much space as the average user's document_root folder, which may be stuffed with bootleg movies or some shit)

Bottom line, don't use this unless you really wanna just play with it and see how it ticks - it is quite interesting.

Here it is on github: https://github.com/hadenodom/php-file-blog

Basically, posts are stored in the posts/ folder, as numbered files with no extension. Just text files. Each numbered file is a post; the higher the number, the more recent the post. The files can have any html in them, nothing is off limits. The first line of each file should be the title, though. I'll explain that in just a second.

Index.php counts the number of files in posts/, and it uses that variable to determine the three most recently uploaded files (based on their names). It displays links to the posts, and reads the three most recent files, and displays the first line out of each file as the text for the link to that post (that's why the first line of the file should be the title). The link goes to "blog.php?post=1" (if you're going to post 1) ; This basically refers you to blog.php with the variable post set at 1.

Blog.php checks for the post variable when it loads. If it's referred to without a post var set, it loads and shows all of the posts (You might wanna make it show only ten or something if you post a lot...) If it's referred with one (such as post=1 in the previous example), it'll load and show that post.

Have fun with this, you guys. And hopefully, you can learn a little bit of PHP file operations by reading through it.


Messages In This Thread
Simple-as-pi PHP blog without a database - by hades - 30-11-2013, 01:04 AM