2012-11-06 2 views
0

안녕하세요. 아래에 기본 captcha 스크립트를 사용했습니다. 내가 직면하고있는 문제는 잘못된 captcha 가치의 영감이 양식이 제출된다는 것입니다. Captcha의 가치가 잘못 입력되면 양식 제출을 막아야합니다.잘못된 captcha 값으로 양식 제출 금지

<?php 
    if(isset($_POST['submit'])) 
{ 
    $hash = (!empty($_POST['hash'])) ? preg_replace('/[\W]/i', '', trim($_POST['hash'])) : ''; // Remove any non alphanumeric characters to prevent exploit attempts 
    $captchacode = (!empty($_POST['captchacode'])) ? preg_replace('/[\W]/i', '', trim($_POST['captchacode'])) : ''; // Remove any non alphanumeric characters to prevent exploit attempts 
    // function to check the submitted captcha 
    function captchaChars($hash) 
    { 
    // Generate a 32 character string by getting the MD5 hash of the servers name with the hash added to the end. 
    // Adding the servers name means outside sources cannot just work out the characters from the hash 
    $captchastr = strtolower(md5($_SERVER['SERVER_NAME'] . $hash)); 
    $captchastr2 = ''; 
    for($i = 0; $i <= 28; $i += 7) 
    { 
     $captchastr2 .= $captchastr[$i]; 
    } 
    return $captchastr2; 
    } 
    if(!empty($captchacode)) 
    { 
    if(strtolower($captchacode) == captchaChars($hash)) // We convert submitted characters to lower case then compare with the expected answer 
    { 
     echo '<h3>The submitted characters were correct</h3>'; 

    } 
    else 
    { 
     echo '<h3>The submitted characters were WRONG!</h3>'; 
     return true; 
    } 

    } 

    else 
    { 
    echo '<h3>You forgot to fill in the code!</h3>'; 
    return true; 
    } 

} 
?> 
+0

양식 처리기의 전체 코드를 게시 해주십시오. 게시 한 내용만으로는 문제를 해결할 수 없습니다. – drew010

답변

0

나는 웹 사이트에서 Captcha를 설치하여 실행 중이며 스팸을 방지하지 못했습니다. 그것은 두려워 스팸 방지 메커니즘으로 타협되었습니다.

그 외에도 captcha가 틀리거나 양식을 제출하지 않으면 false를 반환해야합니다.

+0

나는 그것도 시도했지만 작동하지 않았다. – bhetus

+0

어떤 상태로 떨어지고 있습니까? –