2012-01-06 102 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']:'';?>" 

同爲剩餘..

或者,如果你想有一些其他的網頁上您的驗證邏輯,然後使用會話變量在頁面之間傳遞值... 我希望我回答你是什麼什麼尋找..對於任何其他評論.. :)