2026, 새로운 도약을 시작합니다.

게시판글쓰기, 회원가입 스팸방지

회원글쓰기 게시판에 계속 스팸글이 올라와서 테스트가 가능할때 한번 만들어봤습니다. 마우스움직임이 직선(기계적일 경우 스팸), 선형(사람) 으로 구분해서 hidden input에 값을 넣고 서버에서 다시 체크합니다. 하루 몇천개씩 들어오던 스팸글이 3개 정도 올라왔네요. 

/extend/wv_spam.extend.php

[code]

add_event('tail_sub','wv_spam_honey_spot_add');
add_event('write_update_before','wv_spam_honey_spot_check');
add_event('register_form_update_before','wv_spam_honey_spot_check');

function wv_spam_honey_spot_add(){
    global $bo_table;

    $form_id='';

    if((wv_info('dir')=='bbs' and wv_info('file')=='write' and $bo_table  )){
        $form_id='fwrite';
    }

    if((wv_info('dir')=='bbs' and (wv_info('file')=='register' or wv_info('file')=='register_form')   )){
        $form_id='fregisterform';
    }

    if(!$form_id){
        return;
    }

    include_once G5_BBS_PATH.'/wv_spam_check.php';
}

function wv_spam_honey_spot_check(){

    if(!isset($_POST['wv_h_spot']) or $_POST['wv_h_spot']!='wv'){
        alert('스팸으로 의심되어 등록이 불가합니다.');
    }

}

[/code]

/bbs/wv_spam_check.php

[code]

<script>
    $(document).ready(function () {

        var $form =  $("form#<?php echo $form_id?>[name='<?php echo $form_id?>']");

        let lastX = null;
        let lastY = null;
        let lastDirection = null;
        let straightCount = 0;
        let naturalCount = 0;
        let suspicious = true; // 초기값 true

        const REQUIRED_BOT_COUNT = 80;      // 완벽 직선이 몇 번 이상이면 suspicious 유지
        const REQUIRED_HUMAN_COUNT = 20;    // 자연스러운 움직임이 몇 번 이상이면 해제

        document.addEventListener('mousemove', (e) => {
            if (lastX === null || lastY === null) {
                lastX = e.clientX;
                lastY = e.clientY;
                return;
            }

            const dx = e.clientX - lastX;
            const dy = e.clientY - lastY;

            const direction = [dx, dy];

            const isPerfectLine = (
                (dy === 0 && Math.abs(dx) === 1) ||
                (dx === 0 && Math.abs(dy) === 1) ||
                (Math.abs(dx) === 1 && Math.abs(dy) === 1)
            );

            const isSameDirection = (
                lastDirection &&
                direction[0] === lastDirection[0] &&
                direction[1] === lastDirection[1]
            );

            const isSuspiciousMove = isPerfectLine && isSameDirection;

            if (isSuspiciousMove) {
                straightCount++;
                naturalCount = 0; // 자연스러운 카운터 리셋
            } else {
                naturalCount++;
                straightCount = 0; // 봇 카운터 리셋
            }

            if (!suspicious && isSuspiciousMove && straightCount >= REQUIRED_BOT_COUNT) {
                suspicious = true;
            }

            if (suspicious && naturalCount >= REQUIRED_HUMAN_COUNT) {
                suspicious = false;
            }

            lastX = e.clientX;
            lastY = e.clientY;
            lastDirection = direction;
        });

document.addEventListener('touchmove', (e) => {
    suspicious = false;

});


        $($form).on('submit',function () {
           if(!suspicious){
               $("#wv_h_spot",$form).val('wv');
           }
       })


        $form.prepend('<input type="hidden" name="wv_h_spot" id="wv_h_spot"  value="">');

    })
</script>

[/code]

|

댓글 3개

감사합니다. ^^

테스트 할게요. 감사 합니다.

감사합니다

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

그누보드5 팁자료실

번호 제목 글쓴이 날짜 조회
공지 3년 전 조회 4,598
2741 4일 전 조회 127
2740 5일 전 조회 113
2739 1주 전 조회 217
2738 1주 전 조회 221
2737 1주 전 조회 185
2736 2주 전 조회 284
2735 3주 전 조회 289
2734 3주 전 조회 264
2733 1개월 전 조회 267
2732 1개월 전 조회 303
2731 1개월 전 조회 270
2730 1개월 전 조회 228
2729 1개월 전 조회 359
2728 1개월 전 조회 246
2727 1개월 전 조회 422
2726 1개월 전 조회 260
2725 1개월 전 조회 332
2724 1개월 전 조회 363
2723 1개월 전 조회 267
2722 1개월 전 조회 301
2721 1개월 전 조회 214
2720 2개월 전 조회 304
2719 2개월 전 조회 314
2718 2개월 전 조회 202
2717 2개월 전 조회 337
2716 2개월 전 조회 204
2715 2개월 전 조회 313
2714 2개월 전 조회 273
2713 2개월 전 조회 377
2712 2개월 전 조회 290
🐛 버그신고