PHP comments
Just finished modifying the script and updating this page. Please let me know if anything doesn't work or isn't clear. Thanks!
When you contact me (so I can help you more quickly):
- read this page at least twice
- give me the uri of your site
- create a file named phpinfo.php containing the code <php phpinfo(); ?> (that's all!), upload it to your site, and give me the link to it.
When the popular Blogvoices commenting system looked like it was closing down, the page I got the comments script I am using was no longer available. I decided to publish the code and some explanations here.
I wish I had written this code - but I haven't.. Sascha came up with the script initially, and Tahj added quite a few bits and pieces to it. Other people contributed too - check the original discussion thread at Blogger.
I've added the comments and modified the code slightly at places.
The following code should be copied and saved in a file as "comments.php" (in your root directory you need to rename it!):
Replace "your_email@yourdomain.foo" with your e-mail address so that you are notified whenever somebody posts a comment. [Thanks to Anne for actually writing the line of code which sends the e-mail when I was too lazy to do it myself...]
You can add a link to your site's stylesheet, define BODY.comment H1 and add whatever you want to the HTML part.
The next block of code will be the "annotate.php" file (also in your root directory):
You need to change /path/to/public_html to the path to your public_html directory. Check your phpinfo() if you aren't sure what it is, or e-mail me and I'll give you a hand.
You might want to define a CSS class for BODY.comment P.message.
The following explanations assume that you will create a directory named "comments" inside your root directory to store your comments in. If you are putting your "comments" directory elsewhere (see the note below for a reason why you might want/have to do so), you'll have to modify references to it accordingly.
If your server is running in safe mode, your "comments" directory should be inside the directory containing the file that calls the script. That is because the server will not allow a script to write to a file outside its directory or subdirectories. It means that if you want comments in your archives too, you should place the "comments" directory inside the "archive" directory. If you're not sure what I'm talking about, ignore this and come back to it if you have real trouble getting the script to work.
CHMOD the "comments" directory to 755 if you can - otherwise, 777 is fine.
The last script you need is the one which shows the number of comments to each post (called "countlines"). I've added the JavaScript for the pop-up window in the same file.
You need to copy and paste these scripts somewhere near the top of your page (I put them at the beginning of the body in my blogger template). IE users: view source of countlines.txt to see the code!
Now finally, you want the line which will call up the script and do the magic:
<a title="Post a comment." href="/comments.php?comment=<$BlogItemNumber$>" onclick="commentPopUp(this.href); return false;">
comment <?php $commentfile = $_SERVER['DOCUMENT_ROOT'] . ". "/comments/<$BlogItemNumber$>.comment"; echo countlines("$commentfile",0); ?></a>
Here is one tricky bit: the PHP variable $_SERVER['DOCUMENT_ROOT'] . "/code> might be defined differently on your server. If it doesn't work, you may have to look up the correct variable in your phpinfo().
If you server runs PHP3, you might need to use *.php3 files and modify the scripts accordingly. Plus, don't forget that the page which calls the script must have a "php" extension!
If you aren't using these comments with Blogger, you need to replace <$BlogItemNumber$> with an identification number/word for each post.
There! You have the skeleton - modify and prettify it as you wish. Good luck!
If anything is unclear, if you bump into unexpected trouble, please email me so that I can complete the explanations on this page for other people too!
And of course, this script can also be used without blogger - see what I did in the India section, and simply at the bottom of this page, just below!
Advanced
On my site, I use a little php function I've written which is called "makecomments". When I want to create a comment link like the one below, I just have to type echo makecomment("name_of_comment_file");. Here is the makecomment function (if you're using it, you won't need "countlines" anymore as it does the job too.)



