Are there any recommended PHP libraries or tools for easily implementing CAPTCHA functionality on websites?

Implementing CAPTCHA functionality on websites can help prevent spam and automated bots from submitting forms. There are several PHP libraries and tools available that make it easy to integrate CAPTCHA into your website. Some recommended options include Google reCAPTCHA, Securimage, and Really Simple CAPTCHA.

<?php
// Using Google reCAPTCHA
$siteKey = 'YOUR_SITE_KEY';
$secretKey = 'YOUR_SECRET_KEY';

// Verify the reCAPTCHA response
if(isset($_POST['g-recaptcha-response'])){
    $captcha = $_POST['g-recaptcha-response'];
    $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$captcha");
    $responseKeys = json_decode($response, true);
    if(intval($responseKeys["success"]) !== 1) {
        // CAPTCHA verification failed
        die('CAPTCHA verification failed.');
    }
    // CAPTCHA verification successful, proceed with form submission
}
?>