abc

Share This blog with your friends, so that we can improve more & more . our aim is to easy & simple way of learning.

12/16/2020

How to add captcha - to verify user (image or text capatcha) using html, php, javascript

 step 1) go to google recaptcha website create key from here , which is require for third & fourth step.


step 2)add script between head tag- <script src="https://www.google.com/recaptcha/api.js"></script>


step 3)<div class="g-recaptcha brochure__form__captcha" data-sitekey="YOUR SITE KEY"></div>


step 4) just use below php code.

 <?php

function reCaptcha($recaptcha){

  $secret = "YOUR SECRET KEY";

  $ip = $_SERVER['REMOTE_ADDR'];


  $postvars = array("secret"=>$secret, "response"=>$recaptcha, "remoteip"=>$ip);

  $url = "https://www.google.com/recaptcha/api/siteverify";

  $ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, $url);

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($ch, CURLOPT_TIMEOUT, 10);

  curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);

  $data = curl_exec($ch);

  curl_close($ch);


  return json_decode($data, true);

}


$recaptcha = $_POST['g-recaptcha-response'];

$res = reCaptcha($recaptcha);

if($res['success']){

   // go to page

}



 ?>

 

step 5) test it.

An Introduction to the Laravel Framework: What It Is and Why You Should Use It

  If you're a PHP developer looking for a modern, efficient, and powerful framework to build web applications, look no further than Lara...