【发布时间】: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 替换为生成的实际密钥?这是第一步。之后,您需要修复表格。代码的
-
是的,我已将密钥放在适当的位置,否则我不相信验证码本身会出现。我会尽快尝试您的其他建议。
-
我相信其他代码元素在您描述的位置。
标签: asp-classic captcha recaptcha