【问题标题】:Using reCAPTCHA with Classic ASP将 reCAPTCHA 与经典 ASP 结合使用
【发布时间】:2013-12-21 02:53:56
【问题描述】:

我正在尝试使用这个经典 ASP 示例,但我有 2 个页面,一个是表单页面,另一个是验证页面。我是经典 ASP 的新手,所以我不确定我是否犯了一些语法错误。

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

在我的表单页面上,我正在通过 JS 加载 reCAPTCHA,这部分工作正常。在验证页面上,我有下面的代码。

主要代码(我从 Google 中删除了一些我不会使用的东西,比如用 ASP 生成一个 recaptcha 表单字段)

  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

【问题讨论】:

  • 您不必查询 Server_response 变量而不是 recaptcha_response_field 变量吗?因为 recaptcha_response_field 是用 request.form 参数填充的,当然是 "" 因为用户输入了一个值?
  • 我试过了,但仍然可以提交表单。

标签: asp-classic recaptcha


【解决方案1】:

看来我必须这样做:

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

【讨论】:

    猜你喜欢
    • 2016-11-25
    • 1970-01-01
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    相关资源
    最近更新 更多