boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Hack] Word Verifier for Comments
Goto page 1, 2  Next
 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
Cyberian75



Joined: 26 Sep 2002
Posts: 1285
Location: Oregon

PostPosted: Sat Nov 27, 2004 4:05 am    Post subject: [Hack] Word Verifier for Comments Reply with quote

Have your commenters type in the first word of your post to comment with this hack.

In the "b2comments.post.php" file after the "comment_post_ID" variable, put the following:
Code:
$word = strtolower(trim($HTTP_POST_VARS["word"]));
$postdata = get_postdata($comment_post_ID);
$content = strip_tags($postdata["Content"]);
eregi("[a-z0-9\-]+", $content, $matches);

if (empty($word) || $word != strtolower($matches[0])) {
   setcookie("comment",$comment, time()+30000000);
   echo "Error: the word you entered do not match or is empty.";
   echo "\n<br><br>\n<a href=\"javascript:history.go(-1);\">go back</a>\n\n";
   exit;
} elseif (isset($HTTP_COOKIE_VARS["comment"])) {
   setcookie("comment","", time()-30000000);
}


Then on top of your comment page(s):
Code:
$comment = (empty($HTTP_COOKIE_VARS["comment"])) ? "comment" : $HTTP_COOKIE_VARS["comment"];

right after
Code:
$comment_author_url = (empty($HTTP_COOKIE_VARS["comment_author"])) ? "url" : trim($HTTP_COOKIE_VARS["comment_author_url"]);


Then in your comment form:
Code:
Please enter the <b>first word</b> of this post: <input type="text" name="word" size="10">


And in between the textarea tag:
Code:
<?php echo $comment ?>

_________________
Michael P.



Last edited by Cyberian75 on Sat Dec 11, 2004 1:07 am; edited 6 times in total
Back to top
View user's profile Send private message AIM Address
kiss



Joined: 09 Sep 2004
Posts: 63
Location: Brooklyn

PostPosted: Sat Nov 27, 2004 9:24 am    Post subject: Reply with quote

Awwww Mike you're a genius!!! It works perfectly. Funny thing is I forgot to add <?php echo $comment ?> but it still works. Is that alright?
Back to top
View user's profile Send private message Visit poster's website AIM Address
Cyberian75



Joined: 26 Sep 2002
Posts: 1285
Location: Oregon

PostPosted: Sat Nov 27, 2004 7:35 pm    Post subject: Reply with quote

Yes. Smile
_________________
Michael P.

Back to top
View user's profile Send private message AIM Address
papervixen



Joined: 02 Feb 2003
Posts: 4
Location: Toronto, ON

PostPosted: Sat Nov 27, 2004 7:40 pm    Post subject: Reply with quote

Thanks so much for this! I hope it will help with the 900+ spam e-mails I'm getting a day. *shakes fist*
Back to top
View user's profile Send private message Visit poster's website
Cyberian75



Joined: 26 Sep 2002
Posts: 1285
Location: Oregon

PostPosted: Sat Nov 27, 2004 7:49 pm    Post subject: Reply with quote

Smile
_________________
Michael P.



Last edited by Cyberian75 on Sat Nov 27, 2004 9:45 pm; edited 1 time in total
Back to top
View user's profile Send private message AIM Address
Sigg3



Joined: 03 Jul 2003
Posts: 906
Location: Oslo, Norway

PostPosted: Sat Nov 27, 2004 7:50 pm    Post subject: Reply with quote

papervixen, you should also add this (first post):
http://cafelog.com/board/viewtopic.php?p=25578

..and have a look at b2anti-spam (minus "How to avert bots"..)
http://www.sigg3.net/cafelog/files/b2anti-spam.zip
_________________
Sigg3.net - You know you're worth it! | b2 Cafelog Resource Center | Fight my BattleImp!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
papervixen



Joined: 02 Feb 2003
Posts: 4
Location: Toronto, ON

PostPosted: Sat Nov 27, 2004 7:54 pm    Post subject: Reply with quote

Thank you so much! I'll look into those right away.
Back to top
View user's profile Send private message Visit poster's website
Cyberian75



Joined: 26 Sep 2002
Posts: 1285
Location: Oregon

PostPosted: Sat Nov 27, 2004 8:17 pm    Post subject: Reply with quote

This should be more accurate...
Code:

$word = strtolower(trim($HTTP_POST_VARS["word"]));
$postdata = get_postdata($comment_post_ID);
$content = $postdata["Content"];
eregi("^[a-z0-9]+", $content, $matches);

if (empty($word) || $word != strtolower($matches[0])) {
   setcookie("comment",$comment, time()+30000000);
   echo "Error: the word you entered do not match or is empty.";
   echo "\n<br><br>\n<a href=\"javascript:history.go(-1);\">go back</a>\n\n";
   exit;
} elseif (isset($HTTP_COOKIE_VARS["comment"])) {
   setcookie("comment","", time()-30000000);
}


Could someone test this out?
_________________
Michael P.

Back to top
View user's profile Send private message AIM Address
evelyne



Joined: 12 Dec 2002
Posts: 23
Location: Delft - The Netherlands

PostPosted: Sun Nov 28, 2004 11:37 am    Post subject: testing Reply with quote

I've implemented it at one of my logs. Let you know if there are any troubles. It seem to work for now.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
evelyne



Joined: 12 Dec 2002
Posts: 23
Location: Delft - The Netherlands

PostPosted: Sun Nov 28, 2004 12:07 pm    Post subject: error Reply with quote

the check gives an error when there is no first word, but an image first. Using the first word (which isn't the image for the readers, but the first word after the html) wouldn't work than
_________________
--
Anything About Everything (in Dutch)
http://www.veel-in-een.nl
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
evelyne



Joined: 12 Dec 2002
Posts: 23
Location: Delft - The Netherlands

PostPosted: Sun Nov 28, 2004 12:36 pm    Post subject: just a thought Reply with quote

I thought stripping the html would work, with something like this:

Code:
$search = array ("'<script[^>]*?>.*?</script>'si",  // Strip out javascript
                 "'<[\/\!]*?[^<>]*?>'si",          // Strip out HTML tags
                 "'([\r\n])[\s]+'",                // Strip out white space
                 "'&(quot|#34);'i",                // Replace HTML entities
                 "'&(amp|#38);'i",
                 "'&(lt|#60);'i",
                 "'&(gt|#62);'i",
                 "'&(nbsp|#160);'i",
                 "'&(iexcl|#161);'i",
                 "'&(cent|#162);'i",
                 "'&(pound|#163);'i",
                 "'&(copy|#169);'i",
                 "'&#(\d+);'e");                    // evaluate as php

$replace = array ("",
                 "",
                 "\\1",
                 "\"",
                 "&",
                 "<",
                 ">",
                 " ",
                 chr(161),
                 chr(162),
                 chr(163),
                 chr(169),
                 "chr(\\1)");

$content = preg_replace($search, $replace, $content);

Just after:
Code:
$content = $postdata["Content"];

But I think I miss something, because it isn't working. Someone knows what I miss (echo the $content gives me the content without the html, so it should have worked)
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
evelyne



Joined: 12 Dec 2002
Posts: 23
Location: Delft - The Netherlands

PostPosted: Sun Nov 28, 2004 12:55 pm    Post subject: another small bug Reply with quote

when the first word contains a "-", it will only check for the letters before this sign. The logs I administrate are in dutch. For dutch people something like:
"log-aanbieding"
would be one word. But the check will only work after entering:
log
not with
log-aanbieding

The solution for the problems with the image:
for now I'm not checking on the first word of the content, but the first word of the title. It works for me, because the log where I'm testing uses titles all the time.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Cyberian75



Joined: 26 Sep 2002
Posts: 1285
Location: Oregon

PostPosted: Sun Nov 28, 2004 7:15 pm    Post subject: Reply with quote

"[a-z0-9\-]+" would work.
_________________
Michael P.

Back to top
View user's profile Send private message AIM Address
kiss



Joined: 09 Sep 2004
Posts: 63
Location: Brooklyn

PostPosted: Mon Nov 29, 2004 12:32 am    Post subject: Reply with quote

Umm...which one is better then? The first one or the second one that was posted?
Back to top
View user's profile Send private message Visit poster's website AIM Address
Cyberian75



Joined: 26 Sep 2002
Posts: 1285
Location: Oregon

PostPosted: Mon Nov 29, 2004 12:52 am    Post subject: Reply with quote

The last one. Smile
_________________
Michael P.

Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group