What are some alternative captcha solutions in PHP that are recommended?
One alternative captcha solution in PHP that is recommended is using Google reCAPTCHA. This service provides a more user-friendly experience by presenting users with a simple checkbox to confirm they are not a robot. It also offers better security against automated attacks compared to traditional image-based captchas.
// Google reCAPTCHA site key and secret key
$siteKey = 'YOUR_SITE_KEY';
$secretKey = 'YOUR_SECRET_KEY';
// Verify the user's response with Google reCAPTCHA
$response = $_POST['g-recaptcha-response'];
$remoteIP = $_SERVER['REMOTE_ADDR'];
$recaptchaUrl = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$response&remoteip=$remoteIP";
$recaptchaResponse = json_decode(file_get_contents($recaptchaUrl));
if (!$recaptchaResponse->success) {
// Captcha verification failed
// Handle the error accordingly
} else {
// Captcha verification successful
// Proceed with the form submission
}
Keywords
Related Questions
- What are the advantages and disadvantages of sending PHP contact form data as XML compared to HTML?
- What are some potential security risks of using PHP scripts to transfer files between local and remote computers?
- How can the HTTP-Response in the browser provide insights into why a file download is not working as expected in PHP?