简体   繁体   English

captcha与php会话变量+ jquery验证

[英]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. 我使用它进行表单验证: http ://plugins.jquery.com/project/form-validation-and-hints我使用验证码将代码存储在$ _SESSION ['captchacode']变量中。 what i'm trying to accomplish is to simply check using the jquery validator if user entered good captcha code. 我想要完成的是如果用户输入了良好的验证码,只需使用jquery验证器进行检查。 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. 不要使用jquery进行验证码验证。 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. 您可以使用jquery验证插件的远程方法来检查验证码。 You can see example here - 你可以在这里看到例子 -

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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