Discouraging Comment and Trackback Spam on Geeklog

Tuesday, April 25 2006 @ 02:02 PM MST

Contributed by: gladfelter

My blog is barely visible in the universe and I've already started getting trackback spam. Read on to see what I've done to discourage it.

Tags: trackback, spam

Google and other search engines obey an attribute on links that causes them to ignore the links and not give any "juice" to the websites that are linked to. Comment and trackback spammers try to use your website to give themselves more credibility by putting links to their sites from yours through those comments and trackbacks. Using the "nofollow" attribute prevents this from working. You can still have people posting bogus trackbacks, but at least now they don't gain anything by it.

To implement this in Geeklog v 1.4rc2 I made these changes:

In lib-trackback.php I changed these lines:

} else {
	$template->set_var ('trackback_excerpt', $excerpt);
	$template->set_var ('trackback_excerpt_readmore',
	$excerpt . ' ' . $readmore);
	$template->set_var ('excerpt_br', '');
}
to these lines by adding one line:

} else {
	$excerpt = ereg_replace("<s*a[^>]+href=", "<a rel='nofollow' href=", $excerpt);
	$template->set_var ('trackback_excerpt', $excerpt);
	$template->set_var ('trackback_excerpt_readmore',
	$excerpt . ' ' . $readmore);
	$template->set_var ('excerpt_br', '<br>');
}
In lib-comment.php I changed these lines:

	$A['comment'] = str_replace( '$', '$', $A['comment'] );
	$A['comment'] = str_replace( '{', '{', $A['comment'] );
	$A['comment'] = str_replace( '}', '}', $A['comment'] );
	// Replace any plugin autolink tags
	$A['comment'] = PLG_replaceTags( $A['comment'] );
to these by adding one line:

	$A['comment'] = str_replace( '$', '$', $A['comment'] );
	$A['comment'] = str_replace( '{', '{', $A['comment'] );
	$A['comment'] = str_replace( '}', '}', $A['comment'] );
	$A['comment'] = ereg_replace("<s*a[^>]+href=", "<a rel='nofollow' 
	href=", $A['comment']);
	// Replace any plugin autolink tags
	$A['comment'] = PLG_replaceTags( $A['comment'] );

In formattedcomment.thtml I changed this line:

<a href=""></a>

to this line:

<a rel='nofollow' href=""></a>
 

The rel="nofollow" line tells Google, etc, to not use the link. This is only turned on for comments and trackbacks. Any articles I post will still be followed by search engines, should they ever care to visit!

Tags: Google, Comment, trackback, spam, nofollow, Geeklog

105 comments



http://gladfelter.net/weblog/article.php?story=20060425140244401