기본 ASP에서 reCAPTCHA 사용

중요: reCAPTCHA API 버전 1.0은 더 이상 지원되지 않습니다. 버전 2.0으로 업그레이드하세요. 자세히 알아보기

reCAPTCHA ASP 가이드에서는 ASP 페이지에 보안문자를 간단히 입력하여 봇의 악용을 막을 수 있습니다. 아래 코드는 reCAPTCHA API를 래핑합니다.

API 키를 등록한 후 ASP 페이지 상단에 아래 코드를 붙여넣어 기존 ASP 사이트에 reCAPTCHA를 추가할 수 있습니다.

  <%
  recaptcha_challenge_field  = Request("recaptcha_challenge_field")
  recaptcha_response_field   = Request("recaptcha_response_field")
  recaptcha_public_key       = "your_public_key" ' your public key
  recaptcha_private_key      = "your_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=""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><>" & _ "<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", "https://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 %>

페이지가 로드될 때마다 server_responsenewCaptcha 변수가 설정되므로 페이지 상태를 확인할 수 있습니다.

다음 HTML을 스켈레톤으로 사용할 수 있습니다.

  <html>
  <body>

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

    <% if newCaptcha = False then %>

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

    <% end if %>

    <!-- Generating the form -->
    <form action="recaptcha.asp" method="post">
      <%=recaptcha_challenge_writer()%>
    </form>

  <% else %>

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

  <%end if%>

  </body>
  </html>

추가 자료

  • 디자인 맞춤설정
  • 도움말 및 가이드라인
  • 문제 해결