Recaptcha Konfigurieren

Recaptcha in Joomla und Extensions / Compontents aktivieren

Captcha aktivieren

  1. Captcha ID bei Goole anlegen: https://www.google.com/recaptcha/admin
  2. Captcha in Joomla aktivieren und konfigurieren: https://www.templatemonster.com/help/de/joomla-3-x-how-to-configure-captcha-recaptcha-plugin.html
    1. System -> Global Configuration: Captcha: Recaptcha
    2. Extensions -> Plugin Manager
    3. Recaptcha 2.0 auswählen, Public und Private Key eintragen

Captcha in custom compontent einbauen

Joomla bis 3.4: https://joomla.stackexchange.com/questions/15856/how-can-i-use-google-recaptcha-in-my-custom-page

PHP:
JPluginHelper::importPlugin('captcha');
$dispatcher = JDispatcher::getInstance();
$dispatcher->trigger('onInit','dynamic_recaptcha_1');
HTML:
<div id="dynamic_recaptcha_1"></div>

Validierung:

$post = JFactory::getApplication()->input->post;
$dispatcher = JEventDispatcher::getInstance();
$res=$dispatcher->trigger('onCheckAnswer',$post['recaptcha_response_field']);
if(!$res[0]){
    die('Invalid Captcha');
}

Joomla ab 3.5: https://github.com/joomla/joomla-cms/issues/9544

PHP:
JPluginHelper::importPlugin('captcha');
$dispatcher = JEventDispatcher::getInstance();
$dispatcher->trigger('onInit','my_captcha_div');
HTML:
<div class="g-recaptcha" data-sitekey="ENTER_HERE_SITEKEY" data-theme="light" data-size="compact"></div>
Validierung (bleibt gleich):
$post = JFactory::getApplication()->input->post;
$dispatcher = JEventDispatcher::getInstance();
$res=$dispatcher->trigger('onCheckAnswer',$post['recaptcha_response_field']);
if(!$res[0]){
    die('Invalid Captcha');
}

Eigenbau Captcha: https://www.kaplankomputing.com/blog/tutorials/recaptcha-php-demo-tutorial/

HTML:
<form action="mail.php" method="post" enctype="multipart/form-data">
	<input name="sender_name" placeholder="Your Name..."/>
	<input name="sender_email" placeholder="Your email..."/>
	<textarea placeholder="Your Message..." name="sender_message">
        <div class="captcha_wrapper">
		<div class="g-recaptcha" data-sitekey="YOUR_KEY"></div>
	</div>
	<button type="submit" id="send_message">Send Message!</button>
</form>

PHP:

<?php
	$sender_name = stripslashes($_POST["sender_name"]);
	$sender_email = stripslashes($_POST["sender_email"]);
	$sender_message = stripslashes($_POST["sender_message"]);
	$response = $_POST["g-recaptcha-response"];
	$url = 'https://www.google.com/recaptcha/api/siteverify';
	$data = array(
		'secret' => 'YOUR_SECRET',
		'response' => $_POST["g-recaptcha-response"]
	);
	$options = array(
		'http' => array (
			'method' => 'POST',
			'content' => http_build_query($data)
		)
	);
	$context  = stream_context_create($options);
	$verify = file_get_contents($url, false, $context);
	$captcha_success=json_decode($verify);
	if ($captcha_success->success==false) {
		echo "<p>You are a bot! Go away!</p>";
	} else if ($captcha_success->success==true) {
		echo "<p>You are not not a bot!</p>";
	}

Joomla