-2

我正在尝试在联系表单上实施 reCAPTCHA,但我被卡住了。该功能显示在我的页面上(这很容易),但现在我对如何验证 CAPTCHA 感到困惑。我有一个“send-mail.php”文件来验证输入数据,然后将其发送到指定的电子邮件地址。我应该以某种方式在此文件中包含 reCAPTCHA 验证吗?如果是这样,我该怎么做?

联系表格链接

非常感谢您的帮助。

4

1 回答 1

0

假设您使用的是“官方”PHP 插件(http://recaptcha.net/plugins/php/),这就是我以前使用的:

<?php
    # Get a key from http://recaptcha.net/api/getkey
    $publickey = "";
    $privatekey = "";

    @require_once( 'path/to/recaptchalib.php' );

    # the response from reCAPTCHA
    $resp = null;

    # was there a reCAPTCHA response?
    if( $_POST["recaptcha_response_field"] ) 
    {
        $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);

        if( $resp->is_valid ) 
        {

        } 
        else {
            if( $resp->error == 'incorrect-captcha-sol') {

            }
        }
    }
?>

如果我记得的话,这几乎是源文档中的复制意大利面 - 老实说,我不久前切换到 Akismet ......

于 2013-03-14T04:17:06.220 回答