2012-01-06 97 views
1

我的主页是index.php。我正在使用CAPTCHA,在提交表单后,它会检查CAPTCHA验证,如果该值是正确的,那么它会转到form.php。如果该值不正确,则它将保持在同一页面上。我想使用AJAX功能验证CAPTCHA

我的问题是,如果CAPTCHA值不正确,它涉及到index.php和我已经在窗体中输入的所有值是null。我需要我在表单中输入的值,即使CAPTCHA错误并要求输入新的CAPTCHA文本。

if(empty($_SESSION['6_letters_code']) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) 
{ 
    $errors .= "\n The above code does not match!"; 
} 

if(empty($errors)) 
{ 
    header('Location:form.php'); 
} 

function IsInjected($str) 
{ 
    $injections = array('(\n+)', 
     '(\r+)', 
     '(\t+)', 
     '(%0A+)', 
     '(%0D+)', 
     '(%08+)', 
     '(%09+)' 
    ); 

    $inject = join('|', $injections); 
    $inject = "/$inject/i"; 
    if(preg_match($inject,$str)) 
    { 
     return true; 
    } 
    else 
    { 
     return false; 
    } 
} 

if(!empty($errors)) 
{ 
    header('Location:index.php'); 
    echo "The above code does not match!"; 
} 

回答

0

最简单的方法是把玩具的形式在同一页上的验证脚本,并验证后,如果正确重定向用户浏览器到另一个页面,ELS让他们在同一窗体页上...

现在放入您的输入字段中,假设您使用POST方法发送。

<input type="text" name="username" value="<?php echo isset($_POST['username'])? $_POST['username']:'';?>" 

同为剩余..

或者,如果你想有一些其他的网页上您的验证逻辑,然后使用会话变量在页面之间传递值... 我希望我回答你是什么什么寻找..对于任何其他评论.. :)