2013-12-20 309 views
0

我想使用經典ASP的這個例子,但我有2頁,一個是表單頁面,另一個是驗證頁面。我是傳統ASP中的全新版本,所以我不確定我是否犯了一些語法錯誤。與經典ASP使用reCAPTCHA

https://developers.google.com/recaptcha/docs/asp

在我的表單頁面,我通過JS加載的reCAPTCHA和部分工作正常。在驗證頁面上,我有下面的代碼。

主代碼(我刪除的東西,從谷歌,我是不會使用像生成與ASP一個驗證碼錶單字段)

recaptcha_challenge_field = Request.Form("recaptcha_challenge_field") 
    recaptcha_response_field = Request.Form("recaptcha_response_field") 
    recaptcha_public_key  = "hidden" //your public key 
    recaptcha_private_key  = "hidden" //your private key 

    // returns "" if correct, otherwise it returns the error response 
    function recaptcha_confirm(rechallenge,reresponse) 

    Dim VarString 
    VarString = _ 
      "privatekey=" & recaptcha_private_key & _ 
      "&remoteip=" & Request.ServerVariables("REMOTE_ADDR") & _ 
      "&challenge=" & rechallenge & _ 
      "&response=" & reresponse 

    Dim objXmlHttp 
    Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP") 
    objXmlHttp.open "POST", "http://www.google.com/recaptcha/api/verify", False 
    objXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
    objXmlHttp.send VarString 

    Dim ResponseString 
    ResponseString = split(objXmlHttp.responseText, vblf) 
    Set objXmlHttp = Nothing 

    if ResponseString(0) = "true" then 
    'They answered correctly 
    recaptcha_confirm = "" 
    else 
    'They answered incorrectly 
    recaptcha_confirm = ResponseString(1) 
    end if 

    end function 

    server_response = "" 
    newCaptcha = True 
    if (recaptcha_challenge_field <> "" or recaptcha_response_field <> "") then 
    server_response = recaptcha_confirm(recaptcha_challenge_field, recaptcha_response_field) 
    newCaptcha = False 
    end if 

這就是我想要檢測是否驗證碼是正確的,但它以任何方式提交表格。

if recaptcha_response_field <> "" AND newCaptcha = False then 
// submit form 
Else 
    Response.Write "Error: Please fill out all form fields correctly." 
End If 
+0

沒有你查詢Server_response變量,而不是recaptcha_response_field變量?因爲recaptcha_response_field與request.form參數匹配,當然是<>「」,因爲用戶輸入了一個值? – ulluoink

+0

我試過,但仍然允許表單提交。 – zen

回答

0

好看起來像我不得不這樣做是這樣的:

If server_response = "" AND newCaptcha = False then 
    // Captcha correct 
ElseIf server_response <> "" OR newCaptcha then 
    // Captcha incorrect 
Else 
    // Some other form error 
End If