简体   繁体   中英

captcha with php session variables + jquery validation

i'm working on a contact form. i use this for form validation: http://plugins.jquery.com/project/form-validation-and-hints and i use a captcha that stores the code in $_SESSION['captchacode'] variable. what i'm trying to accomplish is to simply check using the jquery validator if user entered good captcha code. that's how check function works:

function isTypeValid( type, value ) {
var cap = <?php echo $SESSION["captchacode"];?>;
if( type == classprefix + 'Text' ) {        
    return true;
}

if( type == classprefix + 'Captcha' ) {
    if(value==cap){
    return (true);
}else{
    return false;
    }
}   

}

i searched a few threads here and elsewhere and that's where i got

    var cap = <?php echo $SESSION["captchacode"];?>;

from.

i've also tried this:

    var cap = "<%= Session['captchacode'] %>";  

and it didn't help... any ideas?

Don't use jquery for captcha validation. Validate it on the server side.

also, the way you choose (with writing captcha value in the body of the script) is quite funny but it's merely a gift to possible spammer.

You can use remote method of jquery validation plugin to check captcha. You can see example here -

http://jquery.bassistance.de/validate/demo/captcha

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM