SI Captchaで表示される文字を入力すべき文字を分離する。
SI Captchaで表示される文字を入力すべき文字を分離する。
どうやら現在の文字認識技術は予想以上のようです。前回の記事で複雑化させたSI Captchaですが、普通に突破してきます。 そこで今度は表示される文字と入力すべき文字を分離する事にしました。例えば、1+1を表示させて2を入力させる…様に。 今回の改造箇所はこちら
for ( $i = 0; $i < $char_length; $i++ ) {
// this rand character position is a number only so that a 4 letter swear word could never appear
if($i == $rand_pos) {
$pos = mt_rand( 0, strlen( $chars_num ) - 1 );
$char = $chars_num[$pos];
} else {
$pos = mt_rand( 0, strlen( $chars ) - 1 );
$char = $chars[$pos];
}
$displayWord.=$char;
}
//displayWordの最初の一文字を抜いた文字をcaptchaWordとする
$captcha_word=substr($displayWord,1);
if(file_exists($img->captcha_path . $prefix . '.php') && is_readable( $img->captcha_path . $prefix . '.php' ) ) { include( $img->captcha_path . $prefix . '.php' ); $img->captcha_word = $displayWord; } else { $img->captcha_word = $displayWord; }
if ( $fh = fopen( $img->captcha_path . $prefix . '.php', 'w' ) ) {
fwrite( $fh, '<?php $captcha_word = '' . $captcha_word . ''; ?>' );
fwrite( $fh, '<?php $displayWord = '' . $displayWord . ''; ?>' );
fclose( $fh );
@chmod( $img->captcha_path . $prefix . '.php', 0755 );
}
これだけで処理部分はOKですが、何の説明も無しだと正規のコメントも入力出来ません。そこで出力されるhtmlに説明文を書き加えます。
$label_string = ' <label id="captcha_code_label" for="captcha_code">'; $label_string .= ($si_captcha_opt['si_captcha_label_captcha'] != '') ? $si_captcha_opt['si_captcha_label_captcha'] : __('CAPTCHA Code', 'si-captcha'); $label_string .= '(最初の一文字を抜いて記入して下さい。例えばABCDと表示されていたらBCDと入力。大文字小文字は区別しません)'; $label_string .= '</label>';