0

reCaptcha にサインアップし、秘密鍵と公開鍵を取得し、recaptcha.cfm を作成し、フォームにコードを挿入しました。URL にアクセスすると、フォームは完全にレンダリングされますが、その人がキャプチャに何も入力しなくてもフォームは送信されます。これは私の recaptcha.cfm のコードです。recaptcha.cfm の「サンプル」の下に、フォーム ページの関連コードがコメント アウトされています。どんな助けでも大歓迎です。ありがとうございました。

<cfsetting enablecfoutputonly="true">
<!---
    Use the reCAPTCHA API to verify human input.

    reCAPTCHA improves the process of digitizing books by sending words that
    cannot be read by computers to the Web in the form of CAPTCHAs for
    humans to decipher. More specifically, each word that cannot be read
    correctly by OCR is placed on an image and used as a CAPTCHA. This is
    possible because most OCR programs alert you when a word cannot be read
    correctly.

    You will need a key pair from http://recaptcha.net/api/getkey to use this tag.


    Sample
    --------------------------------

        <html>
        <body>

        <cfform>

            <cf_recaptcha
                privateKey="6LepjdQSAAAAAMspsO04gZUXltxddkiI0ZgSF02h"
                publicKey="6LepjdQSAAAAADoLvfvgkwacBAI_GbL-nTy2zvS6">

            <cfinput type="submit" name="submit">

        </cfform>

        <cfif isDefined("form.submit")>
            <cfoutput>recaptcha says #form.recaptcha#</cfoutput>
        </cfif>

        </body>
        </html>


--->

<cfscript>
    CHALLENGE_URL = "http://api.recaptcha.net";
    SSL_CHALLENGE_URL = "https://api-secure.recaptcha.net";
    VERIFY_URL = "http://api-verify.recaptcha.net/verify";
</cfscript>

<cfif not structKeyExists(attributes, "publicKey")>
    <cfthrow type="RECAPTCHA_ATTRIBUTE"
        message="recaptcha: required attribute 'publicKey' is missing">
</cfif>

<cfif not structKeyExists(attributes, "privateKey")>
    <cfthrow type="RECAPTCHA_ATTRIBUTE"
        message="recaptcha: required attribute 'privateKey' is missing">
</cfif>

<cftry>

    <cfparam name="attributes.action" default="render">

    <cfif not listContains("render,check", attributes.action)>
        <cfset sInvalidAttr="action not render|check">
        <cfthrow>
    </cfif>

    <cfset sInvalidAttr="ssl not true|false">
    <cfparam name="attributes.ssl" type="boolean" default="false">

    <cfparam name="attributes.theme" type="regex" pattern="(red|white|blackglass)" default="red">

    <cfif not listContains("red,white,blackglass", attributes.theme)>
        <cfset sInvalidAttr="theme not red|white|blackglass">
        <cfthrow>
    </cfif>

    <cfset sInvalidAttr="tabIndex not numeric">
    <cfparam name="attributes.tabIndex" type="numeric" default="0">

<cfcatch type="any">
    <cfthrow type="RECAPTCHA_ATTRIBUTE"
        message="recaptcha: attribute #sInvalidAttr#">
</cfcatch>
</cftry>

<cfif isDefined("form.recaptcha_challenge_field") and isDefined("form.recaptcha_response_field")>

    <cftry>
        <cfhttp url="#VERIFY_URL#" method="post" timeout="5" throwonerror="true">
            <cfhttpparam type="formfield" name="privatekey" value="#attributes.privateKey#">
            <cfhttpparam type="formfield" name="remoteip" value="#cgi.REMOTE_ADDR#">
            <cfhttpparam type="formfield" name="challenge" value="#form.recaptcha_challenge_field#">
            <cfhttpparam type="formfield" name="response" value="#form.recaptcha_response_field#">
        </cfhttp>
    <cfcatch>
        <cfthrow  type="RECAPTCHA_NO_SERVICE"
            message="recaptcha: unable to contact recaptcha verification service on url '#VERIFY_URL#'">
    </cfcatch>
    </cftry>

    <cfset aResponse = listToArray(cfhttp.fileContent, chr(10))>
    <cfset form.recaptcha = aResponse[1]>
    <cfset structDelete(form, "recaptcha_challenge_field")>
    <cfset structDelete(form, "recaptcha_response_field")>

    <cfif aResponse[1] eq "false" and aResponse[2] neq "incorrect-captcha-sol">
        <cfthrow type="RECAPTCHA_VERIFICATION_FAILURE"
            message="recaptcha: the verification service responded with error '#aResponse[2]#'. See http://recaptcha.net/apidocs/captcha/ for error meanings.">
    </cfif>

<cfelse>

    <cfset form.recaptcha = false>

</cfif>

<cfif attributes.action eq "render">

    <cfif attributes.ssl>
        <cfset challengeURL = SSL_CHALLENGE_URL>
    <cfelse>
        <cfset challengeURL = CHALLENGE_URL>
    </cfif>

    <cfoutput>
    <script type="text/javascript">
    <!--
        var RecaptchaOptions = {
           theme : '#attributes.theme#',
           tabindex : #attributes.tabIndex#
        };
    //-->
    </script>
    <script type="text/javascript"
       src="#challengeURL#/challenge?k=#attributes.publicKey#">
    </script>
    <noscript>
       <iframe src="#challengeURL#/noscript?k=#attributes.publicKey#"
           height="300" width="500" frameborder="0"></iframe><br>
       <textarea name="recaptcha_challenge_field" rows="3" cols="40">
       </textarea>
       <input type="hidden" name="recaptcha_response_field"
           value="manual_challenge">
    </noscript>
    </cfoutput>

</cfif>

<cfsetting enablecfoutputonly="false">
4

1 に答える 1

2

そのカスタム タグはひどく古くなっています。URL は Google によって変更されたため、更新する必要があります。それらを次のように変更します。

CHALLENGE_URL = "http://www.google.com/recaptcha/api";
SSL_CHALLENGE_URL = "https://www.google.com/recaptcha/api";
VERIFY_URL = "http://www.google.com/recaptcha/api/verify";

このカスタム タグの更新版を Gist としてここに投稿しました: https://gist.github.com/2210356

于 2012-07-29T15:01:53.960 に答える