James 3run
Joined: 19 May 2003 Posts: 3756
|
Posted: Mon Dec 11, 2006 5:50 pm Post subject: Ignore this thread |
|
|
TK17 asked me to send you this code with an explanation. It's basically some code I wrote a while back for my own phpBB forums which will add in an extra field to the registration section of the forums asking a simple question like "What is 2 plus 2?". The question may seem simple, but no spam bot would ever be able to answer it (unless someone specifically codes it to answer the question on these forums, but that's unlikely, and if it does happen you can just change the question).
I used to get dozens of spam bots a day, but after adding this script about a month ago, I have not had one register.
Anyway, on to the code. I'm going to write this out in the sort of style of a phpBB MOD instruction file so if you've ever installed one before you should be farmiliar with it.
First you need to add the extra field into the template for the register page:
OPEN templates/subSilver/profile_add_body.php
FIND
Code: | <!-- Visual Confirmation -->
<!-- BEGIN switch_confirm -->
<tr>
<td class="row1" colspan="2" align="center"><span class="gensmall">{L_CONFIRM_CODE_IMPAIRED}</span><br /><br />{CONFIRM_IMG}<br /><br /></td>
</tr>
<tr>
<td class="row1"><span class="gen">{L_CONFIRM_CODE}: * </span><br /><span class="gensmall">{L_CONFIRM_CODE_EXPLAIN}</span></td>
<td class="row2"><input type="text" class="post" style="width: 200px" name="confirm_code" size="6" maxlength="6" value="" /></td>
</tr>
<!-- END switch_confirm --> |
REPLACE WITH
Code: | <!-- Visual Confirmation -->
<!-- BEGIN switch_confirm -->
<!--<tr>
<td class="row1" colspan="2" align="center"><span class="gensmall">{L_CONFIRM_CODE_IMPAIRED}</span><br /><br />{CONFIRM_IMG}<br /><br /></td>
</tr>
<tr>
<td class="row1"><span class="gen">{L_CONFIRM_CODE}: * </span><br /><span class="gensmall">{L_CONFIRM_CODE_EXPLAIN}</span></td>
<td class="row2"><input type="text" class="post" style="width: 200px" name="confirm_code" size="6" maxlength="6" value="" /></td>
</tr>-->
<tr>
<td class="row1"><span class="gen">What is 2 plus 2? *</span><br /><span class="gen_small">4 is the answer.</span></td>
<td class="row2"><input class="post" style="width: 20px" name="confirm_quiz" size="25" maxlength="5" /></td>
</tr>
<!-- END switch_confirm --> |
What we are doing there is basically replacing the image verification code (you won't need it once you have this) with the question field. You can make the question anything you want (even a drop down list of word answers).
Now we need to edit the page that recieves the number they put in so that it knows what to do with their answer.
OPEN includes/usercp_register.php
FIND
Code: | if (empty($HTTP_POST_VARS['confirm_id']))
{
$error = TRUE;
$error_msg .= ( ( isset($error_msg) ) ? '<br />' : '' ) . $lang['Confirm_code_wrong'];
}
else
{
$confirm_id = htmlspecialchars($HTTP_POST_VARS['confirm_id']);
if (!preg_match('/^[A-Za-z0-9]+$/', $confirm_id))
{
$confirm_id = '';
}
$sql = 'SELECT code
FROM ' . CONFIRM_TABLE . "
WHERE confirm_id = '$confirm_id'
AND session_id = '" . $userdata['session_id'] . "'";
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not obtain confirmation code', __LINE__, __FILE__, $sql);
}
if ($row = $db->sql_fetchrow($result))
{
if ($row['code'] != $confirm_code)
{
$error = TRUE;
$error_msg .= ( ( isset($error_msg) ) ? '<br />' : '' ) . $lang['Confirm_code_wrong'];
}
else
{
$sql = 'DELETE FROM ' . CONFIRM_TABLE . "
WHERE confirm_id = '$confirm_id'
AND session_id = '" . $userdata['session_id'] . "'";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Could not delete confirmation code', __LINE__, __FILE__, $sql);
}
}
}
else
{
$error = TRUE;
$error_msg .= ( ( isset($error_msg) ) ? '<br />' : '' ) . $lang['Confirm_code_wrong'];
}
$db->sql_freeresult($result);
}
|
REPLACE WITH
Code: | /* if (empty($HTTP_POST_VARS['confirm_id']))
{
$error = TRUE;
$error_msg .= ( ( isset($error_msg) ) ? '<br />' : '' ) . $lang['Confirm_code_wrong'];
}
else
{
$confirm_id = htmlspecialchars($HTTP_POST_VARS['confirm_id']);
if (!preg_match('/^[A-Za-z0-9]+$/', $confirm_id))
{
$confirm_id = '';
}
$sql = 'SELECT code
FROM ' . CONFIRM_TABLE . "
WHERE confirm_id = '$confirm_id'
AND session_id = '" . $userdata['session_id'] . "'";
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not obtain confirmation code', __LINE__, __FILE__, $sql);
}
if ($row = $db->sql_fetchrow($result))
{
if ($row['code'] != $confirm_code)
{
$error = TRUE;
$error_msg .= ( ( isset($error_msg) ) ? '<br />' : '' ) . $lang['Confirm_code_wrong'];
}
else
{
$sql = 'DELETE FROM ' . CONFIRM_TABLE . "
WHERE confirm_id = '$confirm_id'
AND session_id = '" . $userdata['session_id'] . "'";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Could not delete confirmation code', __LINE__, __FILE__, $sql);
}
}
}
else
{
$error = TRUE;
$error_msg .= ( ( isset($error_msg) ) ? '<br />' : '' ) . $lang['Confirm_code_wrong'];
}
$db->sql_freeresult($result);
}*/
$confirm_quiz = $HTTP_POST_VARS['confirm_quiz'];
if ($confirm_quiz == 4) {
} else {
$error = TRUE;
$error_msg .= ( ( isset($error_msg) ) ? '<br />' : '' ) . 'You answered the quiz question wrong... the answer was 4. It\'s not a trick question, just to prevent spam bots';
}
|
And that's it! The question can now be toggled on and off with the Image Verification checkbox in the admin panel.
I hope this helps stop the spam bots. If you have any problems with it let me know
Thanks,
James _________________
|
|