For future reference, please be aware of the following:
Place the following function in the head of blog.php. This function counts the number of comments in any given comments file.
<?php
function countlines($list,$ctr) {
clearstatcache();
if (file_exists($list)) {
$lines = file($list);
while(list($key, $val) = each($lines)) {
if (stristr ($val, "<!-- comment -->")){
$ctr++;
}
}
}
if ($ctr > 0) return("[".$ctr."]");
}
?>
The next portion is a complicated looking A HREF tag. While it's complicated looking, it's fairly easy to use, note that I've stripped out all the optional attributes for this tag. The href attribute points to my comments.php file (see assumptions 2 and 3 above) and passes it two parameters: dir and comment. The dir parameter is the subdirectory that contains my comments directory (see assumption 4 above). The comment parameter is the name of the comment file, I simply have Blog insert the entry number and use that as the name for my comment file. Next is the target attribute, this will open a new browser window; note that some users find this annoying so use at your own discretion. The next portion is the link text "What do you think?" followed by a php script. The script passes the path to the comment file as a parameter to the countlines function above.
<a
href="/blog/comments.php?&dir=archive&&comment=<$BlogID>"target="_comment">
What do you think?
<?php $commentfile = $DOCUMENT_ROOT .
"/blog/archive/comments/<$BlogID>.comment"; echo countlines("$commentfile",0); ?>
</a>
The heart of this comment system is two files: comments.txt 1KB and annotate.txt 2KB (you'll want to save the links instead of actually opening them - right click|save as). They too have configureable parameters but I will only show the lines in question with a line number as they are long and tedious files. Note that you'll have to change the extension from .txt to .php for these files to actually function (thanks to Greg Miller for pointing out that the original files actually processed instead of simply downloading).
Comments.php sets a cookie on your viewer's computer if they post a comment. The cookie is not vital to the script and may safely be omitted if you choose.
Comments.php lines 30 and 34 can be changed to whatever title you feel is appropriate.
30 <title>What Do You Think?</title> . . . 34 <h1>What Do You Think?</h1>
Annotate.php lines 18, 24, 30, 38, 44 (the commented comment on 44 MUST remain intact) and the form details can all be edited, but I'll leave that up to you to review as practice in working in PHP.