Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Google Recaptcha

Status
Not open for further replies.

axLW

Programmer
Feb 6, 2015
110
GB
Hello, I'm trying to install Google reCAPTCHA on my website.
I found a good example of Classic ASP installation here:

ASP Example

I have made a basic form:

My Form

The problem is, I tick the box, Google confirms I am not a robot and I submit the form.
On the resulting page it then asks me to complete a captcha again, rather than simply display Correct or Wrong.


Can anybody see any loop here that I'm missing:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
 <head>
  <title> New Document </title>
  <script src='[URL unfurl="true"]https://www.google.com/recaptcha/api.js'></script>[/URL]
 </head>

 <body>
  <form method="post" action="result.asp">
	<div class="g-recaptcha" data-sitekey="MY-PUBLIC-KEY"></div>
	<input type="submit" value="SUBMIT" />
  </form>
 </body>
</html>

Code:
<%
 recaptcha_challenge_field  = Request("recaptcha_challenge_field")
 recaptcha_response_field   = Request("recaptcha_response_field")
 recaptcha_public_key       = "MY-PUBLIC-KEY" ' your public key
 recaptcha_private_key      = "MY-PRIVATE-KEY" ' 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=""[URL unfurl="true"]http://www.google.com/recaptcha/api/challenge?k="[/URL] & recaptcha_public_key & """></script>" & _
 "<noscript>" & _
   "<iframe src=""[URL unfurl="true"]http://www.google.com/recaptcha/api/noscript?k="[/URL] & 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", "[URL unfurl="true"]http://www.google.com/recaptcha/api/verify",[/URL] False
 objXmlHttp.setRequestHeader "Content-Type", "application/x-[URL unfurl="true"]www-form-urlencoded"[/URL]
 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

 %>

 <html>
 <body>
 <% if server_response <> "" or newCaptcha then %>
   <% if newCaptcha = False then %>
     <!-- An error occurred -->
     Wrong!
   <% end if %>
   <!-- Generating the form -->
   <form action="form.asp" method="post">
     <%=recaptcha_challenge_writer()%>
   </form>
 <% else %>
   <!-- The solution was correct -->
   Correct!
 <%end if%>
 </body>
 </html>
 
Basically regardless of what happens the first recaptcha (whether right or wrong) sends you to the second recaptcha and the second recaptcha (again regardless of right or wrong) it redirects you back to form.asp without displaying correct or wrong..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top