How can a rechencaptcha be implemented in PHP without using eval?

The issue with using eval in PHP is that it can be a security risk as it allows arbitrary code execution. To implement reCAPTCHA in PHP without using eval, you can directly make a POST request to the reCAPTCHA API and verify the user's response.

// Make a POST request to the reCAPTCHA API to verify the user's response
$response = $_POST['g-recaptcha-response'];
$secretKey = 'YOUR_SECRET_KEY';
$verifyUrl = 'https://www.google.com/recaptcha/api/siteverify';

$data = array(
    'secret' => $secretKey,
    'response' => $response
);

$options = array(
    'http' => array(
        'header' => "Content-type: application/x-www-form-urlencoded\r\n",
        'method' => 'POST',
        'content' => http_build_query($data)
    )
);

$context = stream_context_create($options);
$result = file_get_contents($verifyUrl, false, $context);
$reCaptchaResult = json_decode($result);

if ($reCaptchaResult->success) {
    // reCAPTCHA verification successful, proceed with your code
} else {
    // reCAPTCHA verification failed, handle accordingly
}