Recaptcha V2 under classic ASP
Here’s a quick primer on upgrading your Classic ASP site Recaptcha V1 to V2.
First, go to Google Recaptcha online and generate yourself a v2 pair of keys for your site’s domain.
Next:
On the page with the “FORM” on it on which you want to display the Recaptcha V2.
Add to the HEADER (inside the HEAD TAGS):
<script src='https://www.google.com/recaptcha/api.js'></script>
Replace the existing code which renders your v1 recaptcha with this line:
<div class="g-recaptcha" data-sitekey="put your google public v2 key here" ></div>
on your FORM SUBMIT page (where the v2 form gets submitted to):
Inside ASP tags, place this line:
Response.LCID = 1033 ' USA LCID
It is a required element for the JSON Parser.
Inside the HEAD:
<!--#include file="jsonObject.class.asp" -->
you can get this file from my site HERE
now the processing code to handle the Recaptcha JSON response:
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then Dim recaptcha_secret, sendstring, objXML recaptcha_secret = "your secret key goes here" 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 set jsonObj = new JSONobject set jsonArr = new jsonArray jsonString = objXML.responseText set outputObj = jsonObj.parse(jsonString) if jsonObj.value("success") then Global_Msg="Captcha GOOD!" else Global_Msg="Invalid Recaptcha Response." end if Set objXML = Nothing End If if Global_Msg<>"Captcha GOOD!" then %> invalid RECAPTCHA response. Hit back and try again. <% response.end end if
For your convenience, here is all the code inside one ZIP file.
Let me know if this helped you!