How To Create AJAX Commenting System for Static HTML Pages如何创建Ajax的评论系统,为静态的HTML网页
I wanted to create ajax based commenting system for some html pages.我想创建基于AJAX技术的评论系统,为一些HTML的页面。 The design goals were:设计目标:
1. 1 。 Simple to use and install简单的使用和安装
2. 2 。 Database (MySQL) backed数据库( MySQL的)支持
3. 3 。 Minimal changes to HTML template / files微小的变化,以HTML模板/档案
4. 4 。 Support effective (no frequent cache refreshes) html page compression / caching strategy for heavily commented sites.支持有效的(没有频繁的高速缓存刷新) HTML网页压缩/缓存策略,大量评论的网站。
An AJAX based system fits the bill. 1基于Ajax的制度相适应的条例草案。 The new comments are displayed instantaneously.新的评论显示瞬间。 The html pages can be cached and / or compressed without requiring to refresh after each comment. HTML网页可以被缓存和/或压缩,而不需要重新整理后,每个评论。
Spam is an issue with any commenting system.垃圾邮件的一个问题是,与任何的评论系统。 I have decided to strip html tags in the first iteration to deter spammers.我已决定带HTML标记,在第一次迭代,以遏止垃圾邮件发送者。 As a personal decision I have decided not to capture email address.作为一个个人的决定,我决定不捕捉的电子邮件地址。 However it can be trivially added along with url if so desired.不过可以trivially补充说:随着网址,若有理想。
I used Sajax as my Ajax framework.我用sajax作为我的AJAX框架。 It presented它介绍了 few少数的 problems as Sajax is more suited for PHP / Ruby pages and not HTML.问题sajax更适合对PHP /红宝石的页面,而不是HTML格式。 Here is这里是 my solution我的解决方案 . 。
Schema:架构:
CREATE TABLE `comments` (创建表`评论` (
`id` INT NOT NULL AUTO_INCREMENT , `编号`诠释不空auto_increment ,
`url` VARCHAR( 255 ) NOT NULL , `网址` varchar ( 255 )不空,
`ip` VARCHAR( 30 ) NOT NULL , `叶` varchar ( 30 )不空,
`author` VARCHAR( 255 ) DEFAULT ‘Anonymous Coward’ NOT NULL ,作者` ` varchar ( 255 )默认的'无名氏懦夫'不空,
`location` VARCHAR( 255 ) DEFAULT ‘Cyberspace’ NOT NULL , `位置` varchar ( 255 )默认的'网络'不空,
`comment` TEXT NOT NULL , `评论`文本不空,
`when` TIMESTAMP NOT NULL, `当`时间戳不空,
PRIMARY KEY ( `id` ) )主键( `编号` ) )
); ) ;
Design notes:设计说明:
The code for adding comment passed the url of the page.代码加入评论通过网页的网址。 When the page is loaded a sajax call is made to fetch all the comment for the url of the page.当页面加载1 sajax呼吁作出市值的所有评论的网页的网址。 New comments are displayed instantaneously as new comments are fetched after a comment has been submitted.新的评论显示瞬时作为新的评论是牵强的评论后,已提交。 This can additionally fetch comments from other users.这可以此外,市值评论从其他用户。 However I have decided not to implement timed refresh as that may unnecessarily increase server load without adding much value to users.但我已决定不执行定时刷新,因为这可能会增加不必要的服务器负载增加很大的价值给用户。 Validation checks are made to detect and not add duplicate comments.验证检查作出检测和不添加重复的意见。 Comment throttling by same user can be added to prevent abuse.评论节流由同一用户可以添加,以防止滥用。
Hope that helps in designing your commenting system.希望有助于在设计您的评论系统。
Filed under提起下 CMS Software CMS软件 , , Headline News头条新闻 , , How To如何 , , Open Source Software开放源码软件 , , PHP PHP的 , , Pro Blogging赞成Blogging , , Spam Watch垃圾邮件观赏 , , Tech Note技术说明 , , Web网页 , , Web Services Web服务 | |
| |
RSS 2.0 2.0 | |
Trackback Trackback跟踪 this Article |此文章|
Email this Article电子邮件此文章
You may also like to read您也可以想读 |





June 10th, 2006 at 4:27 pm 2006年6月10日在下午4时27分
I think that works as long as search engine indexing of the comments is not important (as you outlined in “When *NOT* to use AJAX.”我认为,工程,只要搜索引擎索引的评论并不重要, (如您所概述的: “当*不*使用AJAX技术” 。
I don’t understand how stripping markup deters spammers.我不明白如何剥离标记阻止垃圾邮件发送者。 A spambot has no way of knowing whether you are stripping HTML/links or not. 1 spambot无从得知您是否剥离的HTML /链接或没有。 It is just going to submit the spam and hope you leave the HTML intact.它只是去提交的垃圾邮件,并希望你离开的HTML不变。
August 21st, 2006 at 12:15 pm 2006年8月21日在下午12时15分
For antibots the best solution is generating a code automatically in an image.为antibots最好的解决办法是生成一个代码自动在一形象。
August 21st, 2006 at 12:33 pm 2006年8月21日在下午12时33分
@Brian @布赖恩
> I think that works as long as search engine indexing of the comments is not important >我认为,工程,只要搜索引擎索引的评论并不重要,
Definitely.肯定。 That is also a deterrent for spammers.这亦是一种威慑垃圾邮件发送者。
> A spambot has no way of knowing whether you are stripping HTML/links or not. > 1 spambot无从得知您是否剥离的HTML /链接或没有。 It is just going to submit the spam and hope you leave the HTML intact.它只是去提交的垃圾邮件,并希望你离开的HTML不变。
In my experience I have seen most spambots target sites with specific signature like those of WordPress or Movable Type.在我的经验,我所看到的大部分网站服务器今天为Plone的目标与具体的签名一样, WordPress的或活字。 They spam based on site signature.他们的垃圾邮件的基础上网站的签名。 So normally home-grown commenting system are unlikely to be invaded.因此,通常首页成长的评论系统是不可能被入侵。 When they find a popular commenting system is stripping html then they will not have any incentive to develop code for that system.当他们找到一个受欢迎的评论系统是剥离的HTML ,然后他们将不会有任何的激励发展的代码系统。
@Gunther @巩特尔
Do you mean spambots & CAPTCHA?你的意思&服务器今天为Plone的Captcha ?
November 11th, 2007 at 6:56 pm 2007年11月11日在下午6时56分
Thanks谢谢