返信する: PC/WEBの話題
- これでどうかな?(Re:xmobile 書込みがスパム判定
- 投稿者: なーお 投稿日時: 2007/10/15 21:33
どうもこのプラグインの挙動が気になります。
このロジックだと、 100文字(Defo時)以上の文字列の中に日本語がなければ、即スパム扱いです。ところが、xmobileなどURL文字列が長い場合には、例え本文に日本語が書いてあっても、日本語が1文字も無いURLの段階で判断され、スパムと判定されてしまいます。
ループ抜けの判定は、「日本語があること」としておき、日本語があるときはフラグを立て、 ループ外でフラグの有無を評価する方が良さそうだけど。。 この考え、間違っているかなあ・・
***
で、こんな感じかな。。
一応、テストはしてみたけど、判定文字数下限値を、「100」を「40」にしても正常に日本語判定したし、日本語の無い書き込みはハネてくれた。元のコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
foreach( $_POST as $key => $data ) { // dare to ignore arrays/objects if( ! is_string( $data ) ) continue ; $check_length = isset( $lengths[ $key ] ) ? $lengths[ $key ] : $lengths[ 0 ] ; if( strlen( $data ) > $check_length ) { if( strlen( $data ) == mb_strlen( $data ) ) { $this->protector->message .= "No multibyte character was found ($data)\n" ; $this->protector->output_log( 'Singlebyte SPAM' , 0 , false , 128 ) ; die( 'Protector rejects your post, because your post looks like SPAM' ) ; } if( strlen( $data ) > mb_strlen( $data ) ) { $multibyte_ok = true; break; } } } }
変更後のコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
$multibyte_ok = false; foreach( $_POST as $key => $data ) { // dare to ignore arrays/objects if( ! is_string( $data ) ) continue ; $check_length = isset( $lengths[ $key ] ) ? $lengths[ $key ] : $lengths[ 0 ] ; if( strlen( $data ) > $check_length ) { if( strlen( $data ) > mb_strlen( $data ) ) { $multibyte_ok = true; break; } } } if( $multibyte_ok == false) { $this->protector->message .= "No multibyte character was found ($data)\n" ; $this->protector->output_log( 'Singlebyte SPAM' , 0 , false , 128 ) ; die( 'Protector rejects your post, because your post looks like SPAM' ) ; } }