I have a site am working on and I really want to put comment script on it. But I don't want a database.

Recommended Answers

All 2 Replies

Are you asking for help in building one, or asking if we know of one that already exists that doesn't use a database?

If you want to build one without a database, you can use a flat file system (either a collection of many text files for each post, or a single file with all the posts in it).

I personally would prefer using a database like mySQL, but if you insist on using a flat file data format, I'd suggest keeping the comments in a single file (because it will be less overhead as compared to opening hundreds of files).

Store each comment on a new line, so each line represents an individual comment. Anytime someone tries to enter a new line in their comment either replace it write away with a <br/> or replace it with some other character or string of characters to be saved to the file, otherwise their new lines will throw off your script.

You can read a file into an array easily with the file() function in PHP. This reads in a file and puts each line into an element of the array (each line being a comment).

You can separate specific aspects about each comment with a vertical bar; let's say you want to save the user's name, IP address and a time stamp with the comment. A line in your data file could look like:

Lev||1276520027|The site looks nice!<br/>Check out mine if you have a moment

Let's assume you store all the comments like that in a file called "comments.txt"; in PHP you can do this:

$comments = file("comments.txt");
foreach ($comments as $line)
list($name, $ip, $time, $comment) = explode("|", trim($line));
// present a comment here...

Hope that helps - otherwise, let us know specifically what you are after!

Thanks a million, I have never used a forum in my entire life. i just see what I have missed cracking my head without results most time. I created one in a single file but the resolution is a problem. Am using A table of 800px for my site.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.