H Capacha Beispiel
H-Capacha ist eine Alternative zu Googel Captcha. Bei beiden muss man die richtigen Bilder anklicken
Kommentar abgeben zu diesen Beitrag/Code ?Dann hier klicken
Der hier verwendete Code
<?php
// hCAPTCHA API key configuration
$secretKey = 'Insert_hCaptcha_Secret_Key';
$statusMsg = '';
if(isset($_POST['submit'])){
if(!empty($_POST['name']) && !empty($_POST['email'])){
if(!empty($_POST['h-captcha-response'])){
$verifyURL = 'https://hcaptcha.com/siteverify';
$token = $_POST['h-captcha-response'];
$data = array(
'secret' => $secretKey,
'response' => $token,
'remoteip' => $_SERVER['REMOTE_ADDR']
);
$curlConfig = array(
CURLOPT_URL => $verifyURL,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $data
);
$ch = curl_init();
curl_setopt_array($ch, $curlConfig);
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response);
if($responseData->success){
$name = !empty($_POST['name'])?$_POST['name']:'';
$email = !empty($_POST['email'])?$_POST['email']:'';
$message = !empty($_POST['message'])?$_POST['message']:'';
$statusMsg = 'Your contact request has submitted successfully.';
}else{
$statusMsg = 'Robot verification failed, please try again.';
}
}else{
$statusMsg = 'Please check on the CAPTCHA box.';
}
}else{
$statusMsg = 'Please fill all the mandatory fields.';
}
}
echo $statusMsg;
?>
<script src="https://hcaptcha.com/1/api.js" async defer></script>
<form action="" method="post">
<div class="input-group">
<input type="text" name="name" value="" placeholder="Your name" required="" />
</div>
<div class="input-group">
<input type="email" name="email" value="" placeholder="Your email" required="" />
</div>
<div class="input-group">
<textarea name="message" placeholder="Type message..."></textarea>
</div>
<!-- Add hCaptcha CAPTCHA box -->
<div class="h-captcha" data-sitekey="1e324959-86c3-49fc-a5ca-93935be005b8"></div>
<input type="submit" name="submit" value="SUBMIT">
</form>