Help me with reCaptcha

Hello,
I’m a .net intermediate developer with no knowledge of php unfortunately.
However, there’s a very simple script here to embed reCaptcha to my website:

I’ve embedded and it’s showing on my website correctly, I just can’t check the response:
All provided sample files are uploaded but on this line of contact.php:

$recaptcha = new ReCaptcha\ReCaptcha(“secret_key”);

I get this error_log:
PHP Fatal error: Uncaught Error: Class ‘ReCaptcha\ReCaptcha’ not found in /home2/mainUSER/public_html/site.com/contact.php:50

Can’t figure out, please help :frowning:

There are several (easy) steps needed to implement reCaptcha…

1.) import the class
2.) add the element/control to the form
3.) Validation

You also need your private and site keys from google.

Hey thx for the reply but not helpful :frowning:

Here’s my php script that I wrote awhile back ago for Google ReCaptcha 2.0 (I believe).

<?php

require_once 'assets/config/config.php';
require_once "vendor/autoload.php";

use Miniature\sendMail;

/*
 * The below must be used in order for the json to be decoded properly.
 */
$data = json_decode(file_get_contents('php://input'), true);

$token = $data['token'];

if (hash_equals($_SESSION['token'], $data['token'])) {
    /* The Following to get response back from Google recaptcha */
    $url = "https://www.google.com/recaptcha/api/siteverify";

    $remoteServer = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_SANITIZE_URL);
    /*
     * g-response is from $data['response'] that was sent over using FETCH
     */
    $response = file_get_contents($url . "?secret=". PRIVATE_KEY . "&response=" . $data['response'] . "&remoteip=" . $remoteServer);
    $recaptcha_data = json_decode($response);
    /* The actual check of the recaptcha */
    if (isset($recaptcha_data->success) && $recaptcha_data->success === TRUE) {
        /*
         * If token matches and ReCaptcha is valid then send to an email
         * php script or php class. I personally use Swiftmailer, but you can use
         * another 3rd Party Mailer or write you own email script (I wouldn't
         * recommend it).
         */
        $data['message'] =
            '<html lang="en">' .
            '<body style=\'background: #eee;\'>' .
            '<p style="font-size: 1.8em; line-height: 1.5;">' . $data['name'] . '<br>' . $data['email'] . '<br>' . $data['phone'] . '<br>' . $data['website'] . '<br> Subject of Email is ' . $data['reason'] . '</p>' .
            '<p style="font-size: 1.6em; line-height: 1.5;">' . $data['comments'] . '</p>' .
            '<p style="font-size: 1.4em; line-height: 1.5;">Thank You, for taking your time to contact me! I will get back to you as soon as I can.<br> Best regards, John Pepp</p>' .
            '</body>' .
            '</html>';
        $send = new sendMail();

        $result = $send->sendEmail($data);

        /* Send Back Result (true or false) back to Fetch */
        if ($result) {
            output(true);
        } else {
            errorOutput(false);
        }
    } else {
        $success = "You're not a human!"; // Not on a production server:
    }
} else {
    output('Token Error');
}

function errorOutput($output, $code = 500) {
    http_response_code($code);
    echo json_encode($output);
}


/*
 * After converting data array to JSON send back to javascript using
 * this function.
 */
function output($output) {
    http_response_code(200);
    echo json_encode($output);
}

It might help you out a little? (The code needs a little cleaning up, but like I said I wrote this awhile back)

Sponsor our Newsletter | Privacy Policy | Terms of Service