Hacks: Xoops Comments - Prevent Anonymous User Spam

Posted by: attockon 2007/9/22 7:36:32 10499 reads Although there is option in every module that would let you choose who can post a comment. But what if you want anonymous users to post comments as well. There isn't any option (at least I couldn't find any) that will prevent anonymous users from spamming. So this hack will prevent spam if a url\link is found in anonymous users' post.

As always recommended while playing with hacks, make sure you backup the file you will be editing. In this case its: XOOPS_ROOT_DIR\Include\comment_post.php

Note: I have tested it only on Xoops 2.0.16


Start...

1) Open XOOPS_ROOT_DIR\Include\comment_post.php


2) Look for the following on line 138

Original Code
break;
case 
"post":

   
$doimage 1;
    
$comment_handler =& xoops_gethandler('comment');
    
$add_userpost false;
    
$call_approvefunc false;
    
$call_updatefunc false;





3) Change it to ...
break;
case 
"post":

    
//myhack - Prevent Anonymous User Spam
    //if a URLLINK is found in link, then dont let annonymous user post.
    
$myhack_comment $_POST['com_text'];
    
$myhack_title $_POST['com_title'];
    
//checking if poster is anonymous
    
if (!is_object($xoopsUser)) {
        if (
preg_match("/http/",$myhack_comment) || preg_match("/www/",$myhack_comment) || preg_match("/href/",$myhack_comment) || preg_match("/http/",$myhack_title) || preg_match("/www/",$myhack_title)) {
            echo 
"Dont Spam Bitch!!!!!";
            exit();    
        }
        else {
        }
    }
    
//end of myhack


    
$doimage 1;
    
$comment_handler =& xoops_gethandler('comment');
    
$add_userpost false;
    
$call_approvefunc false;
    
$call_updatefunc false;