【问题标题】:Google reCAPTCHA Validation Issue (accepts anything including blank)Google reCAPTCHA 验证问题(接受任何内容,包括空白)
【发布时间】:2014-11-04 16:43:21
【问题描述】:

我正在尝试在经典 ASP 网站上实施 Google 的 reCAPTCHA,并尝试遵循此处的指南大纲: https://developers.google.com/recaptcha/docs/asp

按照该页面上的说明,我已将此代码添加到包含表单的页面顶部:

 <%
 recaptcha_challenge_field  = Request("recaptcha_challenge_field")
 recaptcha_response_field   = Request("recaptcha_response_field")
 recaptcha_public_key       = "<font color=red>your_public_key</font>" ' your public key
 recaptcha_private_key      = "<font color=red>your_private_key</font>" ' your private key
 ' returns the HTML for the widget
 function recaptcha_challenge_writer()
 recaptcha_challenge_writer = _
 "<script type=""text/javascript"">" & _
 "var RecaptchaOptions = {" & _
 "   theme : 'red'," & _
 "   tabindex : 0" & _
 "};" & _
 "</script>" & _
 "<script type=""text/javascript"" src=""http://www.google.com/recaptcha/api/challenge?k=" & recaptcha_public_key & """></script>" & _
 "<noscript>" & _
   "<iframe src=""http://www.google.com/recaptcha/api/noscript?k=" & recaptcha_public_key & """ frameborder=""1""></iframe><br>" & _
     "<textarea name=""recaptcha_challenge_field"" rows=""3""cols=""40""></textarea>" & _
     "<input type=""hidden"" name=""recaptcha_response_field""value=""manual_challenge"">" & _
 "</noscript>"
 end function
 ' 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

%>

此外,根据该页面,我已将此代码添加到表单本身以生成 reCAPTCHA 小部件:

 <% if server_response <> "" or newCaptcha then %>

    <% if newCaptcha = False then %>

      <!-- An error occurred -->
      Wrong!

    <% end if %>

      <%=recaptcha_challenge_writer()%>

  <% else %>

    <!-- The solution was correct -->
    Correct!

  <%end if%>

我可以让 CAPTCHA 正确显示,但它没有验证 - 它会接受任何答案,包括留空。我认为需要将一些代码添加到我的脚本中以实际处理数据,但不确定将其放置在哪个代码或位置。

我尝试将上述代码中似乎用于验证目的的部分移动到处理响应并生成电子邮件的脚本中,但也没有成功。

可在此处查看 for 页面: http://www.onlyproforma.com/mktimg/landingPage_ResultsFirst4_CAPTCHA.asp

我知道还有其他选项,但如果可能的话,我希望让这个选项正常工作。

非常感谢任何帮助。

【问题讨论】:

  • 可以在 Classic ASP 中实现 recaptcha。请分享您迄今为止尝试过的代码。
  • 我已经编辑了原始帖子,以在提供的链接中包含以前引用的代码。
  • 您是否已将 recaptcha_public_key 和 recaptcha_private_key 替换为生成的实际密钥?这是第一步。之后,您需要修复表格。代码的
    行在另一个表单中。应该只有一个表单,并且代码的第二位 "" 或 newCaptcha then %> 等应添加到发布表单的页面中。希望对您有所帮助。
  • 是的,我已将密钥放在适当的位置,否则我不相信验证码本身会出现。我会尽快尝试您的其他建议。
  • 我相信其他代码元素在您描述的位置。

标签: asp-classic captcha recaptcha


【解决方案1】:

我遇到了类似的问题,尤其是新的 reCAPTCHA 勾选功能。如果您查看为您提供公钥和私钥(秘密)密钥的 reCAPTCHA 管理站点,您会发现要验证的服务器端集成 URL 与上面的代码不同。在上面的代码中,验证 URL 是 _http://www.google.com/recaptcha/api/verify 而 reCAPTCHA 管理页面提供的验证 URL 是 _https://www.google.com/recaptcha/api/siteverify .很不一样。

另外,所需的参数也不同。在上面的代码中,有一个对 Request("recaptcha_challenge_field") 和 Request("recaptcha_response_field") 的调用。然而,新的 reCAPTCHA 验证只需要响应字段。但即使这样也变了!现在是 request.form("g-recaptcha-response")。

当然,您在上面使用的代码直接来自 Google 自己 (https://developers.google.com/recaptcha/old/docs/asp)。但看起来这段代码已经过时了,特别是如果你认为它被归档在一个名为 OLD 的目录中。

所以这对我有用!

Dim recaptcha_secret
recaptcha_secret = "your secret code"

Dim sendstring
sendstring = _
   "https://www.google.com/recaptcha/api/siteverify?" & _ 
   "secret=" & recaptcha_secret & _
   "&response=" & request.form("g-recaptcha-response")

Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.Open "GET", sendstring , false

objXML.Send()

下面的代码读取来自 Google 的响应。回复以 JSON 对象的形式返回,但我无法在服务器端读取或处理 JSON 响应,也找不到简单的方法。

所以解决方法是搜索字符串“true”。如果它返回 TRUE(正),则确认 reCAPTCHA。如果它不返回 TRUE,那么响应本质上是 FALSE 并且 reCAPTCHA 未正确提交。

它很丑,但它有效:

if instr(objXML.responseText,"true") then
        response.redirect "to an appropriate page"           
    else
        response.redirect "to an appropriate page"           
end if

也许有一种更简洁的方式来阅读 Google 回复,但我已经对其进行了测试,它对我有用。

完整的代码如下所示:

<%
Dim recaptcha_secret
recaptcha_secret = "your secret code"

Dim sendstring
sendstring = _
   "https://www.google.com/recaptcha/api/siteverify?" & _ 
   "secret=" & recaptcha_secret & _
   "&response=" & request.form("g-recaptcha-response")

Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.Open "GET", sendstring , false

objXML.Send()

if instr(objXML.responseText,"true") then
        response.redirect "to an appropriate page"           
    else
        response.redirect "to an appropriate page"           
end if
%>

【讨论】:

    【解决方案2】:

    以下代码将进入表单发布的页面。即在你的情况下 L_Landing_actionJCR.asp

    <% if server_response <> "" then %>
      Wrong!
    <% else %>
      Correct!
    <% else %>
    

    【讨论】:

    • 谢谢你,但这没有用。我在我的头上,会考虑其他选择。不过,我非常感谢您的帮助。
    猜你喜欢
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-31
    相关资源
    最近更新 更多