Block-Spam-By-Math升级版DIY
2011-09-15 TECH
原版Block-Spam-By-Math只是用rand函数随机产生了了2个整数(mathvalue0、mathvalue1)算加法(mathvalue2)
rand函数参考:http://www.w3school.com.cn/php/func_math_rand.asp
...... function add_hidden_fields() { $mathvalue0 = rand(2, 15); $mathvalue1 = rand(2, 15); echo '<div>'; echo "What is $mathvalue0 + $mathvalue1 ?"; echo '<input name="mathvalue2" type="text" />'; echo '<strong>IMPORTANT!</strong> To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)</div>'; echo '<div style="display: none;">Please leave these two fields as-is: '; echo "<input name="mathvalue0" type="text" value="$mathvalue0" />"; echo "<input name="mathvalue1" type="text" value="$mathvalue1" />"; echo '</div>'; } ...... // Check for hidden fields and wp_die() in case of error function check_hidden_fields() { // Get values from POST data $val0 = ''; $val1 = ''; $val2 = ''; if ( isset( $_POST['mathvalue0'] ) ) { $val0 = $_POST['mathvalue0']; } if ( isset( $_POST['mathvalue1'] ) ) { $val1 = $_POST['mathvalue1']; } if ( isset( $_POST['mathvalue2'] ) ) { $val2 = $_POST['mathvalue2']; } // Check values if ( ( $val0 == '' ) || ( $val1 == '' ) || ( intval($val2) != (intval($val0) + intval($val1)) ) ) { // Die and return error 403 Forbidden wp_die( 'Bye Bye, SPAMBOT!', '403 Forbidden', array( 'response' => 403 ) ); } } ......
如何改造复杂一点呢?
直接增加计算复杂程度就好了:加减乘除,甚至你可以平方立方,平方根立方根
我所用的方法:2个随机整数A、B先放大N倍算加法再缩小N倍然后减一个随机数C
即 (A*N + B*N)/N – C
N完全是一个无需在input中体现出来的数字,但是复杂程度已经大大增加了,如果你想继续复杂你可以继续放大再缩小 加了再减。。随便你
目前效果: 已经100%杜绝SPAM
...... function add_hidden_fields() { $mathvalue0 = rand(1, 11); $mathvalue1 = rand(1, 21); $mathvalue2 = rand(1, 31); $mathvalue2=$mathvalue2*3; $mathvalue3 = rand(1, 41); $mathvalue3=$mathvalue3*4; echo '<div style="border: 1px solid #EEE; border-left: 10px solid #EEE; border-right: 10px solid #EEE; line-height: 25px; padding: 5px; margin: 0px;">'; echo "<span style="color: red;"><strong>Required: (".($mathvalue0*$mathvalue2)."+".($mathvalue1*$mathvalue2).")/$mathvalue2-".$mathvalue3."=</strong></span>"; echo '<input name="mathvalue2" size="3" type="text" />'; echo '</div>'; echo '<div style="display: none;">Please leave these two fields as-is: '; echo "<input name="mathvalue0" type="text" value="$mathvalue0" />"; echo "<input name="mathvalue1" type="text" value="$mathvalue1" />"; echo "<input name="mathvalue3" type="text" value="$mathvalue3" />"; echo '</div>'; } ...... // Check for hidden fields and wp_die() in case of error function check_hidden_fields() { // Get values from POST data $val0 = ''; $val1 = ''; $val2 = ''; if ( isset( $_POST['mathvalue0'] ) ) { $val0 = $_POST['mathvalue0']; } if ( isset( $_POST['mathvalue1'] ) ) { $val1 = $_POST['mathvalue1']; } if ( isset( $_POST['mathvalue2'] ) ) { $val2 = $_POST['mathvalue2']; } if ( isset( $_POST['mathvalue3'] ) ) { $val3 = $_POST['mathvalue3']; } // Check values if ( ( $val0 == '' ) || ( $val1 == '' ) || ( $val3 == '' ) || ( intval($val2) != (intval($val0)+intval($val1)-intval($val3)) ) ) { // Die and return error 403 Forbidden wp_die( 'Bye Bye, SPAMBOT!', '403 Forbidden', array( 'response' => 403 ) ); } } ......
暂无评论