0

my captcha field

<p style="height:30px;"><img id="captcha" src="includes/secureimage/securimage_show.php?sid=<?php echo md5(time()); ?>" alt="CAPTCHA Image" />
<a tabindex="-1" style="border-style: none; margin-left:5px;" href="#" title="Refresh Image" onclick="document.getElementById('captcha').src = 'includes/secureimage/securimage_show.php?sid=' + Math.random(); return false"><img src="images/refresh.png" alt="Reload Image" onclick="this.blur()" style="vertical-align: top; border:0;" /></a></p></div>
<p><label for="seccode">Verification Code:<span class="important">*</span></label><input id="seccode" type="text" name="seccode" size="10" class="required" /></p>

my jquery validate plugin code for captcha

seccode: {
        required: true,
        remote: {
        url: "checkuser.php",
        type: "post",
        data: {
        seccode: function() {
            //alert($("#seccode").val());
            return $("#seccode").val();
        }
    }
}
}

my php

if($_POST['seccode'])
    {
        $securimage = new Securimage();
        return $securimage->check($_POST['seccode']);
    }

i am using securimage for captcha. message for required condition for captcha is working. but remote condition is not working. Ofcourse i have included required class file in php and also started session_start() in the start of php file.

[note] the error gone now. something new comes now. First time the captcha works when i focus out, but after that it continues to callback the validation method on each change.. see the firebug output below...

GET http://localhost:8080/property/html/captcha.php?seccode=pzubwg
GET http://localhost:8080/property/html/captcha.php?seccode=pzubwg

200 OK
        36ms    
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=l
GET http://localhost:8080/property/html/captcha.php?seccode=l

200 OK
        39ms    
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=ln
GET http://localhost:8080/property/html/captcha.php?seccode=ln

200 OK
        41ms    
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnr
GET http://localhost:8080/property/html/captcha.php?seccode=lnr

200 OK
        36ms    
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnrg
GET http://localhost:8080/property/html/captcha.php?seccode=lnrg

200 OK
        38ms    
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgu
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgu

200 OK
        32ms    
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgue
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgue

200 OK
        25ms    
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgu
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgu

200 OK
        34ms    
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnrg
GET http://localhost:8080/property/html/captcha.php?seccode=lnrg

200 OK
        40ms    
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgv
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgv

200 OK
        42ms    
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgve
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgve

200 OK
        37ms

2 Answers 2

3

Basically when your jquery validates the captcha code, the captcha code is destroyed in the very same function where the validation occurs. Thats why i was getting the problem. The code works fine once you refresh the captcha again.

Sign up to request clarification or add additional context in comments.

Comments

1

Validation requires you to return "true" if the remote validation was successful, also I prefer using different server-side checking for remote validations just like this demo.

So the captcha validation will be, post_captcha.php:

<?php
session_start();
include_once 'securimage/securimage.php';

$securimage = new Securimage();
if ($securimage->check($_POST['seccode']) == false) {
    // the code was incorrect
    // handle the error accordingly with your other error checking
    // or you can do something really basic like this
    //die('The code you entered was incorrect.  Go back and try again.');
    echo "false";
} else {
    echo "true";
}
?>

Open the demo link and with your firebug enabled and only submit the username field with any username and then check it with one of the taken usernames (for e.g. "asdf"), you will notice that the responses it just like my post_captcha.php responses!

Ibrahim

8 Comments

ok i created another file captcha.php, i entered the above code there, but it keeps on giving me false always. i checked the session vlaues and they are right on their place. what can be the problem then
can you setup a test page? or paste your form and captcha.php files on pastebin.com ?
here is the form pastebin.com/AH8UtVs5 here is the captcha.php pastebin.com/Gnnp9YVy here is the jquery pastebin.com/FwNQAWHd
your code seems to work just fine man, I've made an example on my host here I've disabled username and email remote checking and used include_once in the captcha post file and it's working just fine!
Also, I've added these two line to the securimage_show.php file: $img->perturbation = 0.1; and $img->num_lines = 0; to make the captcha more visible for testing purposes
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.