在经典ASP上使用reCAPTCHA [英] Using reCAPTCHA with Classic ASP

查看:166
本文介绍了在经典ASP上使用reCAPTCHA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use this example of classic ASP but I have 2 pages, one is form page, the other is verify page. I'm a total newb at classic ASP so I'm not sure if I'm making some syntax errors or not.

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

在我的表单页面上,我正在通过JS加载reCAPTCHA,并且该部分工作正常.在验证页面上,我有以下代码.

On my form page, I'm loading reCAPTCHA via JS and that part is working fine. On the verify page, I have the code below.

主代码(我从Google删除了我不想使用的东西,例如用ASP生成Recaptcha表单字段)

Main code (I removed stuff from Google that I wasn't going to use like generate a recaptcha form field with 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

这是我试图检测验证码是否正确的地方,但是它以任何一种方式提交.

This is where I'm trying to detect if captcha is correct, but it submits form either way.

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

推荐答案

好吧,看来我必须这样做:

Well looks like I had to do it this way:

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

这篇关于在经典ASP上使用reCAPTCHA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆