UBB.Dev
Posted By: arentzen CAPTCHA newpost & reply - 03/27/2007 1:59 AM
Hej
This post will describe how to install a captcha in newpost and replies, so its possible to allow anonymous posters, without open your forum for spambots. The capatcha will thus only have effect for anonumous posters. Registrated users can ignore captcha.

Its provided that you have uploaded:
audit.php
button.php

If you havent, you can download them here. You can read about the captcha and test it here http://php.webmaster-kit.com/

Modified files
addpost.php
addpost.php(language file)
newpost.php
newpost.php (language file)
newreply.php
newreply.php (language file)
newpost.tmpl
newreply.tmpl
addpost_prewiev.tmpl


Step 1.
open addpost.php(language file) and add the lines
Code

$ubbt_lang['NO_CAPTCHA'] = "Wrong digits";
$ubbt_lang['ENTER_DIGITS'] = "Enter digits if you're not logged in";

Step 2.
Open newpost.php( language file) and add the line
Code

$ubbt_lang['ENTER_DIGITS'] = "Enter digits if you're not logged in";

Step.3
Open newrely.php(language file) and add the line
Code

$ubbt_lang['ENTER_DIGITS'] = "Enter digits if you're not logged in";

Step.4
Open newpost.tmpl and newreply.tmpl and add the captcha and digit input box
Code


<br/>
<img width="120" height="30" src="button.php" border="1" />




<b>
{$ubbt_lang['ENTER_DIGITS']}
</b>


<input type="text" maxlenght="5" size="5" name="userdigit" class="formboxes" value="" />




Step.5
NOTE!In addpost_prewiev.tmpl, the captcha has to be put into 2 places, because you have 2 options. One option to send the post, and a option to edit the post. You may not exclude one of them, otherwise it will not work!
Code
<?  //UBBTREMARK
echo <<<UBBTPRINT

<table width="{$theme['tablewidth']}" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
<table cellpadding="{$theme['cellpadding']}" cellspacing="{$theme['cellspacing']}" width="100%" class="tableborders">
<tr>
<td class="tdheader">
{$ubbt_lang['PREV_POST']}
</td>
</tr>
</table>
</td>
</tr>
</table>

<table width="{$theme['tablewidth']}" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
{$template['form1']}
<table cellpadding="{$theme['cellpadding']}" cellspacing="{$theme['cellspacing']}" width="100%" class="tableborders">
<tr class="darktable">
<td>
{$ubbt_lang['POST_BODY']}
</td>
</tr>
<tr class="lighttable">
<td>





<table width="100%" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
<table cellpadding="{$theme['cellpadding']}" cellspacing="{$theme['cellspacing']}" width="100%" class="tableborders">
<tr>
<td class="subjecttable">
$iconurl $PrintSubject
</td>
</tr>
<tr class="lighttable">
<td>


$PrintBody

</td>
</tr>
</table>
</td>
</tr>
</table>

<input type="hidden" name="Subject" value="$FormSubject" />
<input type="hidden" name="Body" value="$FormBody" />
<input type="hidden" name="Parent" value="$Parent" />
<input type="hidden" name="Main" value="$Main" />
<input type="hidden" name="postername" value="$postername" />
<input type="hidden" name="Cat" value="$Cat" />
<input type="hidden" name="Reged" value="$Reged" />
<input type="hidden" name="Board" value="$Board" />
<input type="hidden" name="IP" value="$IP" />
<input type="hidden" name="what" value="$what" />
<input type="hidden" name="page" value="$page" />
<input type="hidden" name="view" value="$view" />
<input type="hidden" name="oldnumber" value="$oldnumber" />
<input type="hidden" name="sb" value="$sb" />
<input type="hidden" name="o" value="$o" />
<input type="hidden" name="mail" value="$mail" />
<input type="hidden" name="PStatus" value="$PStatus" />
<input type="hidden" name="Sticky" value="$Sticky" />
<input type="hidden" name="Icon" value="$Icon" />
<input type="hidden" name="frompreview" value="0" />
<input type="hidden" name="vc" value="$vc" />
<input type="hidden" name="fpart" value="$fpart" />
<input type="hidden" name="replyto" value="$replyto" />
<input type="hidden" name="convert" value="$convert" />
{$template['attachfile']}
{$template['fileinput']}




<img width="120" height="30" src="button.php" border="1" />




<b>
{$ubbt_lang['ENTER_DIGITS']}
</b>


<input type="text" maxlenght="5" size="5" name="userdigit" class="formboxes" value="" />



<input type="submit" value="{$ubbt_lang['TEXT_CONT']}" class="buttons" />

</td>
</tr>
</table>
</form>
</td>
</tr>
</table>







<table width="{$theme['tablewidth']}" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
<table cellpadding="{$theme['cellpadding']}" cellspacing="{$theme['cellspacing']}" width="100%" class="tableborders">
<tr class="darktable">
<td>
{$ubbt_lang['EDIT_MORE']}
</td>
</tr>
<tr class="lighttable">
<td>
{$template['form2']}
{$ubbt_lang['SUBJECT_TEXT']}


<input type="text" name="Subject" value="$Subject" class="formboxes" />


<!-- The following 2 template vars are defined in addpost.php -->
<!-- This is necessary because post icons are a config option -->

{$ubbt_lang['POST_TEXT']}


<textarea cols="$TextCols" rows="$TextRows" class="formboxes" wrap="soft" name="Body">$Body</textarea>







<input type="hidden" name="postername" value="$postername" />
<input type="hidden" name="Cat" value="$Cat" />
<input type="hidden" name="Reged" value="$Reged" />
<input type="hidden" name="Board" value="$Board" />
<input type="hidden" name="what" value="$what" />
<input type="hidden" name="page" value="$page" />
<input type="hidden" name="view" value="$view" />
<input type="hidden" name="Main" value="$Main" />
<input type="hidden" name="Parent" value="$Parent" />
<input type="hidden" name="sb" value="$sb" />
<input type="hidden" name="o" value="$o" />
<input type="hidden" name="fpart" value="$fpart" />
<input type="hidden" name="vc" value="$vc" />
<input type="hidden" name="replyto" value="$replyto" />
<input type="hidden" name="oldnumber" value="$oldnumber" />
<input type="hidden" name="convert" value="$convert" />

<!-- The following template var is defined in addpost.php -->
<!-- This is necessary because it is not always displayed -->
{$template['emailoption']}
<input type="checkbox" name="preview" value="1" $Pselected class="formboxes" />
{$ubbt_lang['DO_PREVIEW']}
{$template['canattach']}
.



<img width="120" height="30" src="button.php" border="1" />




<b>
{$ubbt_lang['ENTER_DIGITS']}
</b>


<input type="text" maxlenght="5" size="5" name="userdigit" class="formboxes" value="" />




<input type="submit" value="{$ubbt_lang['TEXT_CONT']}" class="buttons" />
</form>


</td>
</tr>
</table>
</td>
</tr>
</table>
UBBTPRINT;
/* UBBTREMARK */ ?>

Step.6
Open addpost.php and add the code just before these lines
// -----------------------------------------------------
// Now if we are doing a preview of the post, we do this


Code

//------------------------------------------------------------
// Captcha - af Arentzen
if( ($config['anonnames']) && (!$Username) ) {
include "audit.php";
if(audit()){
}
else {
$html -> not_right($ubbt_lang['NO_CAPTCHA'],$Cat);
}
}

Step.7
Open newpost.php and newreply.php and put in a "dummy code" in the middle of the scripts, so you dont get error message when executing the scripts.
Code

//---------------------------------------------------------------------------
// Reset captcha ved besvarelse - af Arentzen
if( ($config['anonnames']) && (!$Username) ){
include "audit.php";
if(!audit()){
}
}

Then we are finish. You should now be able to open your forum for anonymous without collecting spamposts from spambots...
Please leave a comment if you have trouble understanding or further modifications to this guide.

Enjoy!
Posted By: Gizmo Re: CAPTCHA newpost & reply - 03/27/2007 2:57 AM
Looks great, good job smile
© UBB.Developers