Part of the EllisLab Network
pMachine Pro has been replaced by ExpressionEngine, our full featured web publishing solution. Please consider upgrading.
You can download pMachine Pro here: Download pMachine Pro  |  Download Language Packs
   
 
CAPTCHA for pMachine Free 2.3
Posted: 21 December 2004 12:25 AM   [ Ignore ]  
Summer Student
Total Posts:  4
Joined  2004-12-20

Hi Folks. 1st, by way of introduction, check out my blog.

I’ve implemented a Turing test anti-spam tool for my comments. Now, I’m a good enough programmer to know that this is not the most elegant solution. I’d renamed the members.php script in desperation, and so I was in a hurry to hack something together so I could undo that. I’m one of those bloggers who doesn’t want to require registration.

Anyways, to implement this, if you want to try it out, 4 files need editing. And you need to snag the images. Note that my webhost doesn’t have the mime type properly configured for gzipped tarballs, so you’ll have to shift-click, or something like that (I have no idea what works in IE or Opera).

Let’s see if I can describe this in a useful way. But before I do, let me just add a disclaimer and some other necessary cruft.

Use at your own risk. I make no warranty or representation that this will work for anybody. I assume no responsibility of liability for any damages of any kind.

License You can use this code any way you want. It’s free. You may not sell it, or any code derived from it. Keep it free.

Testing I haven’t done anything like exhaustive testing. My web host is running Apache 1.3.29 and PHP 4.3.10. My test machine is Apache 2.0 with PHP 4.3.4. If your web host is running an old (really old) PHP, things like $_POST might not be there. Easy enough to mod, in that case, but don’t say I didn’t warn you.

Limited fuctionality This blocks only unregistered users. Shouldn’t be too tough to make it work regardless of registration status. Well, I was in a hurry. smile

For the record I haven’t looked at anyone else’s CAPTCHA code. I suspect it looks better anyway. And I didn’t feel like diving into generating images on the fly. I mean, yeah it’s cool to do that sort of stuff. I try to keep things simple when I can.

Now that that’s out of the way ... <phew>

in pm/inc.lib.php - add the following at the end of the “DEFINE DEFAULT VARIABLES” section

//      JSB: Stuff for turing test
if (!isset($alanuser))   $alanuser = '';
if (!isset(
$alancheck))  $alanuser = '';

in pm/language/english/messages.php - add this at the end, before the closing ?> It’s all one line, I’ve broken it up so it doesn’t whack out the display here.

$L_MESSAGE['900'] = "Turing test failure. If you're a real human
commenter, please try again. If you're a comment spammer,
crawl back into your cesspool and don't come out again. $backlink"
;

in pm/lib/comment.fns.php
1) in the function weblog_comment_form, after the globals (well, that’s where I put it) add (again, all one line, unless you prefer to break after the commas—doesn’t really matter with this one anyway)

//      JSB Turing test array for images
$tuname = array ('happy.gif', 'grumpy.gif', 'sleepy.gif',
'doc.gif', 'bashful.gif', 'dopey.gif', 'sneezey.gif', 'bert.gif',
'ernie.gif', 'alan.gif');


2) find this code at about line 200

if ($formtype != 0)
        
$require_reg = 'no';

    if (
$require_reg == "no")
    
{


and add the following right after it (before the $my_name = htmlspecialchars(stripslashes($my_name));)

//      JSB: adding turing test generation

// (note the next is all one line, broken here)

        
$form .= '<div class="human">Are you human?<br /><br />
If so, enter the following number when submitting your comment.
Don\'
t bother with it if you\'re going to preview. It\'s required only
when you hit the submit button
.<br /><br />';

// (end all one line section)

        for ($i = 1; $i <= 5; $i++) {
          $n = rand(0, 9);
          $tstring .= $n;
          $form .= '
<img src="images/alan/';
          $form .= $tuname[$n];
          $form .= '"
/>';
        }

// (another statement all on one line)

        $form .= '
&nbsp;&nbsp;<input type="text" name="alanuser" size=5
maxlength
=5 /><input type="hidden" name="alancheck" value="';

// (end all on one line)

        $form .= md5($tstring);
        $form .= '"
/></div>';

//      end turing mods


and, in pm/lib/comment.add.php, at about line 162
immediately after

//      ---------------------------------------------
//              IF REGISTRATION IS NOT REQUIRED
//      ---------------------------------------------

if ($require_reg == "no")
{


insert the following (before if (($preview == 0) && (timelock(”{$weblog}_comments”)==false)))

//      JSB Turing test check
    
if (($_POST['submit'] == " SUBMIT ") && (md5($alanuser) != $alancheck)) {
      
return header("location:$memdir$messagespage$sfx?m=900");
    
}

Create the directory images/alan (note, not pm/images/alan), copy that tarball into it, and untar it using `tar zxvf turing_images.tgz`. If you on a Windows host, well, what can I say.

That should do it. If you find this useful, hey, cool! And if so, maybe you could throw a link my way? I mean, don’t feel like you have too, but it’d be appreciated.

Profile
 
 
Posted: 21 December 2004 10:46 AM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  4
Joined  2004-12-20

Just FYI, nearly as soon as I re-enabled commenting, I got a pile of spam comments. So, I’ll be looking at how they got around this.

Profile
 
 
Posted: 21 December 2004 03:46 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  4
Joined  2004-12-20

After finding some really obvious bugs, I think I have this working now—no comment spam since I figured things out. I’m going to play with a bit more before I post the code.

Profile
 
 
Posted: 23 December 2004 06:09 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  4
Joined  2004-12-20

Here’s the fixed code.

Changes to pm/language/english/messages.php - same as above. Remember, it’s all one line, not 3. It’s broken into 3 lines for posting here only so it doesn’t mess up the forum display width.

Images: same as above.

The rest of this assumes a “vanilla” version of the files to be modified. That is, I’m going to describe it as if the mods I describe above aren’t there, and you haven’t modded the files in some other way.

in pm/inc.lib.php - add the following at the end of the “DEFINE DEFAULT VARIABLES” section, i.e. right before the MASTER INCLUDES.

//  JSB: Stuff for turing test
$fluffer = 'replace this string';
if (!isset(
$alanuser))   $alanuser = '';
$alanuser .= $fluffer;
if (!isset(
$alancheck))  $alancheck = '';


and change the contents of $fluffer there on the first line, where the value is assigned. It isn’t terribly critical that this string is different for everybody’s blog, but it’s good if it is. So make up something fun.

in pm/lib/comments.fns.php
1) in the function weblog_comment_form, after the globals (well, that’s where I put it) add the following (again, all one line, unless you prefer to break after the commas—doesn’t really matter with this one anyway) This is below line 30.

//      JSB Turing test array for images
$tuname = array ('happy.gif', 'grumpy.gif', 'sleepy.gif',
'doc.gif', 'bashful.gif', 'dopey.gif', 'sneezey.gif', 'bert.gif',
'ernie.gif', 'alan.gif');


2) 2) find this code at about line 200 or 203

if ($formtype != 0)
    
$require_reg = 'no';
if (
$require_reg == "no")
    
{


and add the following right after it (before the $my_name = htmlspecialchars(stripslashes($my_name));)

//  JSB: adding turing test generation

// (note, the following is all on one line, even though it's broken into many lines here)
        
$form .= '<div class="human">Are you human?<br /><br />If so,
enter the following number when submitting your comment. Don\'
t bother with it if
you\'re going to preview. It\'s required only when you hit the submit button.
<
br /><br />';
// (end of what'
s all on one line)

        for (
$i = 1; $i <= 5; $i++) {
          $n
= rand(0, 9);
          
$tstring .= $n;
          
$form .= '<img src="images/alan/';
          
$form .= $tuname[$n];
          
$form .= '" />';
        
}

// (note, the following is all on one line, even though it's broken into many lines here)
        
$form .= '&nbsp;&nbsp;<input type="text" name="alanuser" size=5 maxlength=5
/><input type="hidden" name="alancheck" value="'
;
// (end of what's all on one line)

        
global $fluffer;
        
$form .= md5($tstring.$fluffer);
        
$form .= '" /></div>';

//  end turing mods


and, in pm/lib/comment.add.php, at about line 162
immediately after

//      ---------------------------------------------
//              IF REGISTRATION IS NOT REQUIRED
//      ---------------------------------------------

if ($require_reg == "no")
{


insert the following (before if (($preview == 0) && (timelock(”{$weblog}_comments”)==false)))

//  JSB Turing test check
    
    
if (isset($submit)) {
        $submit
= trim($submit);
    
        if ((
$submit == 'SUBMIT') && (md5($alanuser) != $alancheck)) {
            
return header("location:$memdir$messagespage$sfx?m=900");
        
}
        
if ($submit != 'SUBMIT') {
            
return header("location:$memdir$messagespage$sfx?m=900");
        
}
    }


There, that’s better. Apologies for the really dumb things I missed the first time around.

This has been running now for a couple days on my blog, and the minor change I just made and uploaded is trivial enough that if it passes the quickie tests I’ve given it, it’s good to go.

I also have to request that anyone using this mod, post any bug reports here, and not on my blog. Any reports posted to my blog will be deleted without comment.

If you get errors such as: “unexpected T_STRING on line 204” in ‘comment.fns.php’” it’s probably because of stuff that needs to be on one line, but isn’t. So make sure, after you copy and paste the code from here, that you recombine into one line those code statements where so directed. Note the comment lines bracketing the lines which are broken up for display purposes.

Profile
 
 
Posted: 24 December 2004 05:01 AM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  2
Joined  2002-11-26

hi…

i’ve followed the instructions on the last post…

but it doesn’t work on mine ^^;

it doesn’t require that you input the captcha at all.

Profile
 
 
Posted: 24 December 2004 05:45 AM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  2
Joined  2002-11-26

err… sorrry. nevermind, i figured it how. i forgot i was logged in while testing. thanks!

Profile
 
 
Posted: 25 December 2004 05:27 PM   [ Ignore ]   [ # 6 ]  
Summer Student
Total Posts:  1
Joined  2004-12-25

Thanks a lot for your solution. So far it seems to work like charm!

Profile
 
 
Posted: 05 January 2005 03:02 AM   [ Ignore ]   [ # 7 ]  
Summer Student
Avatar
Total Posts:  17
Joined  2003-06-05

Thanks FreedomSight, now i use captcha for my coment blog. realy its more nice than my “little script to block coment”
my weblog

 Signature 

Poetry Source | Property Search | busby seo challenge |
Free vector

Profile
 
 
Posted: 12 January 2005 12:51 PM   [ Ignore ]   [ # 8 ]  
Summer Student
Total Posts:  6
Joined  2005-01-12

Fatal error: Cannot instantiate non-existent class: email in /home/sv_visitsendk/pm/lib/comment.add.php on line 620


after implemented CAPTCHA I get this error warning ..

the comment are working but only after refreshing the page .
Any ideas of why this occurs ??

Profile
 
 
Posted: 12 January 2005 03:23 PM   [ Ignore ]   [ # 9 ]  
Summer Student
Total Posts:  6
Joined  2005-01-12

hmm could it be that I forgot to upload in ascii ??

Profile
 
 
Posted: 14 January 2005 08:44 AM   [ Ignore ]   [ # 10 ]  
Summer Student
Total Posts:  6
Joined  2005-01-12

Problem solved

Some files where missing..

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 233, on December 18, 2007 12:04 AM
Total Registered Members: 64967 Total Logged-in Users: 0
Total Topics: 81989 Total Anonymous Users: 0
Total Replies: 440671 Total Guests: 15
Total Posts: 522660    
Members ( View Memberlist )
Active Members: