javascript-jQuery Real Person-总是失败

无论我输入什么(甚至是正确的验证码),我总是会得到不匹配的输出.我试过回显值(如果您输入正确的代码,它们应该匹配).而且我总是得到这样的东西:

6952304285049
-1247767175

>我正在使用jquery-1.10.2.min.js(并将它与realperson.js文件一起链接在我的标头中)
http://gfishdesigns.com/COMP2920/_COMPLETED/Assignment%202/SignUp.php

这是我的代码(我还要做一些其他验证):

<?php
include 'Header.php';
include 'Database.php';
?>
<script type="text/javascript">
    $(function() {
        $('#defaultReal').realperson();
    });
</script>

<h1>Sign Up</h1>

<?php

if ($_POST){

    $username = $_POST['username'];
    $password = $_POST['password'];
    $check = '';

    //validate CAPTCHA
    function rpHash($value) { 
        $hash = 5381; 
        $value = strtoupper($value); 
        for($i = 0; $i < strlen($value); $i++) { 
        $hash = (($hash << 5) + $hash) + ord(substr($value, $i)); 
        } 
        return $hash; 
    } 
      if (rpHash($_POST['defaultReal']) == $_POST['defaultRealHash']) { ?>
        <p class="accepted">You have entered the "real person" value correctly and the form has been processed.</p>
<?php 

    //if username is not blank
    if($username != ''){

        //check if username exists already
        $query = "SELECT username FROM tbl_user;";
        $result = mysql_query($query) or die(mysql_error());
        while ($record = mysql_fetch_row($result))
        {
            foreach($record as $field)
            {
                if($field == $username){
                    //if user exists, dont let them add same user
                    $error_message_username = 'username already used; choose a unique name';
                }
                else{
                    $check = 'pass';
                }
            }
        }   
    }else{
        $error_message_username = 'username cannot be blank';
    }

    //if password is not blank
    if($password != ''){    
        $error_message_password = '';

        // encrypt password
        $encrypted_password = md5($password);   

        if($check == 'pass'){
            //set username and password into database
            $query = "INSERT INTO tbl_user VALUES('','".$username."','".$encrypted_password."');";
            $result = mysql_query($query) or die(mysql_error());
        }
    }else{
        $error_message_password = 'password cannot be blank';
    }



    } else { ?>
            <p class="rejected">You have NOT entered the CAPTCHA value correctly and the form has been rejected.</p>
    <?php 
echo rpHash($_POST['defaultReal']) . '<br/>';
echo $_POST['defaultRealHash'];

}

}    

?>

<form method="post" action="SignUp.php">
  <p>
    E-Mail:
    <input type="text" class="required email" id="username" name="username">
    <?php 
    if ( $error_message_username != '' ) {
        print "$error_message_username";
    }
    ?>
  </p>
  <p>
    Password:
    <input type="text" name="password">
            <?php 
    if ( $error_message_password != '' ) {
        print "$error_message_password";
    }
    ?>
  </p>
  <p>
    CAPTCHA:
    <input type="text" id="defaultReal" name="defaultReal">
  </p>
  <p>
    <button class="mybutton" type="submit" value="Sign Up">Sign Up</button>
  </p>
</form>

解决方法:

提供了php rpHash函数的两个版本,一个用于32位,一个用于64位PHP.运行phpinfo,并确保您使用的是此页http://keith-wood.name/realPerson.html所提供函数的正确版本.此处使用的按位函数将在32位和64位计算机上返回不同的值.参见本页:http://www.php.net/manual/en/language.operators.bitwise.php

上一篇:PHP-允许Google绕过CAPTCHA验证-是否明智?


下一篇:网站验证码自动识别