Captcha Purpose :
captcha basically use for protect unwanted spam attach and unwanted person hacker,
today trend on captcha code mostly use in signup, sign in process,contact us page etc as per user depend reuirement.
Note : reCAPTCHA is not working on local or localhost, please run code on live server.
What is reCAPTCHA?
reCAPTCHA is a free service that protects your website from spam and abuse. reCAPTCHA uses an advanced risk analysis engine and adaptive CAPTCHAs to keep automated software from engaging in abusive activities on your site. It does this while letting your valid users pass through with ease.
client side integration link are paste in your page which is show in step 1 in google and paste into header tag your projects,
Advantage :
1-main things is reCAPTCHA is prevent spam,
2-robotics attack,
3-essay understand to human,
4-advance sequirites,
5-human effort channeling the time spend solving captcha into digitizing text,
6-captcha can not read by computer,
7-recaptcha is digitizing text,building machine learning datasets,
reCAPTCHA offers more than just spam protection. Every time our CAPTCHAs are solved, that human effort helps digitize text, annotate images, and build machine learning datasets. This in turn helps preserve books, improve maps, and solve hard AI problems.
Easy to add, advanced security
reCAPTCHA is a free service that protects your site from spam and abuse. It uses advanced risk analysis techniques to tell humans and bots apart. With the new API, a significant number of your valid human users will pass the reCAPTCHA challenge without having to solve a CAPTCHA. reCAPTCHA comes in the form of a widget that you can easily add to your blog, forum, registration form, etc.
Powered by machine learning
Hundreds of millions of CAPTCHAs are solved by people every day. reCAPTCHA makes positive use of this human effort by channeling the time spent solving CAPTCHAs into digitizing text, annotating images, building machine learning datasets. This in turn helps preserve books, improve maps, and solve hard AI problems.
Best link :
https://www.google.com/recaptcha/intro/invisible.html
Google recaptcha documenation :
https://developers.google.com/recaptcha/docs/verify
Demo link :
http://freeteachnology.hol.es/captcha/
Code link :
https://drive.google.com/file/d/0BxmTZPVcu72faGdZWDVqaGxoWlU/view?usp=drive_web
Create reCaptcha using following steps :
1-Go to link and create sitekey entering Site title,Site url,Owner name of site
Link : http://www.google.com/recaptcha/
2-after that click on getCaptcha key link,
3-register new website input label,reCapctah V2 select,enter domian name,check captcha term and condition,and click on register button ,
Following image show form of captcha registration :
select site key and screte key,
create following folder structure as :
1-header.php,
2-index.php,
3-footer.php,
4-action.php,
1-header.php :
Header.php file include bootstrap link and css and js file
Code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content='FreeTeachnology is a programming blog maintained by Disuza Jen. Tutorials focused on Programming, Jquery, Ajax, PHP, Demos, Web Design, Javascript, and MySQL.' name='description'/>
<meta content='java script, web development, web design, web programming, jquery ajax, ajax php, jquery ajax demos, jquery demos, regular expression, ajax demos, ajax programming, tutorials, php script, ajax tutorial, ajax examples, jquery tutorial, database, mysql, web database development, blogger, google ajax api, google visualization, google app, rss,API, technology, coding, code, examples, php programming, facebook scripts, twitter API, facebook like, twitter scripts, form validation, hosting, form submit, validation, free scripts, free hosting, sql script, programming, jsp, tomcat, SMTP Mail, Oauth, freeteachnology.blogsopt , freeteachnology, freeteachnology Programming' name='keywords'/>
<meta content='disuza jen' name='author'/>
<title>How to Integrate Google "reCAPTCHA" on Your Website</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.1.1.js" integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA=" crossorigin="anonymous"></script>
<link href="validation/error.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<!-- start:header -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid" id="freeteachnology">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="#">Free Teachnology</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home <span class="sr-only"></span></a></li>
<li><a href="#">About us</a></li>
<li><a href="#">Contact us</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
2-footer.php :
Footer link include validation link and social link :
Code :
<!-- Start::footer -->
<footer>
<div class="footer footer-bottom">
<div class="container">
<p class="pull-left"> Copyright © <?php echo date('Y');?>. Design and Develop by - Disuza Jen. </p>
<div class="pull-right">
<ul class="nav nav-pills payments">
<li>
<a target="blank" href="https://www.facebook.com/profile.php?id=100011576444095">
<i class="fa fa-facebook"></i></a>
</li>
<li>
<a target="blank" href="https://plus.google.com/116407769803493244155">
<i class="fa fa-google"></i></a>
</li>
<li>
<a target="blank" href="https://twitter.com/disuzajen1">
<i class="fa fa-twitter"></i></a></li>
<li>
<a target="blank" href="https://plus.google.com/116407769803493244155">
<i class="fa fa-link"></i>
</a>
</li>
</ul>
</div>
</div>
</div>
<!--/.footer-bottom-->
</footer>
<script src="validation/jquery.validate.js"></script>
<script src="validation/googlecaptcha.js"></script>
<!-- End::footer -->
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css">
</body>
</html>
3-index.php :
Index file show form of submit and simple code of recaptcha code which is placed in index.php files :
Captcha code :
Code :
<div class="g-recaptcha" data-sitekey="6Lfteh0UAAAAADMs-GVK2uZwJSFjelPbgUQfylYm"></div>
This div generated google and placed sitekey which is created.
Captcha js placed in header of index.php file :
Code :
<!-- Google recaptcha js link -->
<script src='https://www.google.com/recaptcha/api.js'></script>
<!-- Google recaptcha js link →
Captcha code value access using jquery :
Code :
Var captcha=$('#g-recaptcha-response').val();
And in php access value :
<?php
$captcha=$_POST[‘g-recaptcha-response'’];
?>
Following simple code of index.php files :
Code :
<?php include('header.php'); ?>
<body>
<div>
<br><br><br>
<?php
session_start();
if (!empty($_SESSION['statusMsg'])) {
echo '<p>' . $_SESSION['statusMsg'] . '</p>';
unset($_SESSION['statusMsg']);
}?>
<!-- Google recaptcha js link -->
<script src='https://www.google.com/recaptcha/api.js'></script>
<!-- Google recaptcha js link -->
<div class="cleafix"></div>
<div class="container">
<div class="alert alert-info">
<strong>Hi..</strong> How to Integrate Google "reCAPTCHA" on Your Website
</div>
<div class="alert alert-warning">
<a href="https://drive.google.com/open?id=0BxmTZPVcu72faGdZWDVqaGxoWlU" class="btn btn-xs btn-warning pull-right" target="blank();">Click</a>
<strong> Code download link-</strong>
</div>
<br><br>
</div>
<div class="clearfix"></div>
<div class="container">
<div class="panel-body">
<form action="" enctype="multipart/form-data" class="form-horizontal" id="googlecaptcha" name="googlecaptcha" method="post" >
<label id="shows"></label>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">First Name</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="fname" name="fname" placeholder="First name">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Last Name</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="lname" name="lname" placeholder="Last name">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Mobile</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="email" name="email" placeholder="Email ID">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Address</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="address" name="address" placeholder="Addess">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Captcha</label>
<div class="col-sm-6">
<div class="g-recaptcha" data-sitekey="6Lfteh0UAAAAADMs-GVK2uZwJSFjelPbgUQfylYm"></div>
<label id="captchMsg"></label>
</div>
</div>
<input type="hidden" name="action_type" value="add"/>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-primary" name="submit" id="submit" value="Submit"/>
<input type="reset" class="btn btn-default" value="Cancel" />
</div>
</div>
</form>
</div>
</div>
</div>
<?php include('footer.php'); ?>
If user can click on captcha link then captcha popup show as follow :
4-googlecaptcha.js :
Google captcha js file placed in validation folder,create code of jquery validation and form submit value post on action page ,
Code :
jQuery(document).ready(function () {
$("#googlecaptcha").validate({
rules: {
fname: {
required: true,
},
lname: {
required: true,
},
mobile: {
required: true,
number:true,
maxlength:10,
minlength:10
},
email:{
required: true,
email: true,
},
address: {
required: true,
},
},
messages: {
fname: {
required: "* Please enter first name.",
},
lname: {
required: "* Please enter last name.",
},
mobile: {
required: "* Please enter mobile no.",
number: "* Please enter only number.",
minlength: "* Mobile no should be minimum 10 digit.",
maxlength: "* Mobile no should be maximum 10 digit."
},
email:{
required: "* Please enter email.",
email:"* Enter email id is correct."
},
address: {
required: "* Please enter address.",
},
},
submitHandler : function(form) {
var fname = $.trim($('#fname').val());
var lname = $.trim($('#lname').val());
var mobile = $.trim($('#mobile').val());
var email = $.trim($('#email').val());
var address = $.trim($('#address').val());
var recaptcha = $.trim($('#g-recaptcha-response').val());
if(recaptcha=="")
{
$("#captchMsg").text("* Captcha is empty.").css("color","red");
}
$.ajax({
type: "POST",
url: "add-action.php",
async: true,
data: {fname:fname,lname:lname,mobile:mobile,email:email,address:address,recaptcha:recaptcha},
success: function(html) {
if(html==0) {
alert('Enter captcha correct value.');
} else if(html==1) {
alert('Form submited.');
}
}
});
}
});
});
5-add-action.php :
Action file value access which is form from in index.php files ,google captcha value access and store in one variable and validate captcha value following ways :
Code :
<?php
//start::capctch code
$secret = "6Lfteh0UAAAAAJBcWJoDuO0Bxw30E8dqPtFuNqp9";
$ip = $_SERVER['REMOTE_ADDR'];
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $catpctha);
//print_r($verifyResponse);
$responseData = json_decode($verifyResponse);
$responseData->success;
?>
Get response true and false
Full code of action files :
<?php
// echo '<pre>';
// print_r($_POST);
// die;
$submit = $_POST['submit'];
//Post data value::-
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$address = $_POST['address'];
$catpctha = (isset($_POST['recaptcha']) ? $_POST['recaptcha'] : '');
//start::capctch code
$secret = "6Lfteh0UAAAAAJBcWJoDuO0Bxw30E8dqPtFuNqp9";
$ip = $_SERVER['REMOTE_ADDR'];
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $catpctha);
//print_r($verifyResponse);
$responseData = json_decode($verifyResponse);
//End::capctch code
if ($responseData->success) {
echo '1';
exit();
}else {
echo '0';
exit();
}
?>
I hope that you can understand very well and refer my code thanks,if you like my code please share and comment,
Thanks
captcha basically use for protect unwanted spam attach and unwanted person hacker,
today trend on captcha code mostly use in signup, sign in process,contact us page etc as per user depend reuirement.
Note : reCAPTCHA is not working on local or localhost, please run code on live server.
What is reCAPTCHA?
reCAPTCHA is a free service that protects your website from spam and abuse. reCAPTCHA uses an advanced risk analysis engine and adaptive CAPTCHAs to keep automated software from engaging in abusive activities on your site. It does this while letting your valid users pass through with ease.
client side integration link are paste in your page which is show in step 1 in google and paste into header tag your projects,
Advantage :
1-main things is reCAPTCHA is prevent spam,
2-robotics attack,
3-essay understand to human,
4-advance sequirites,
5-human effort channeling the time spend solving captcha into digitizing text,
6-captcha can not read by computer,
7-recaptcha is digitizing text,building machine learning datasets,
reCAPTCHA offers more than just spam protection. Every time our CAPTCHAs are solved, that human effort helps digitize text, annotate images, and build machine learning datasets. This in turn helps preserve books, improve maps, and solve hard AI problems.
Easy to add, advanced security
reCAPTCHA is a free service that protects your site from spam and abuse. It uses advanced risk analysis techniques to tell humans and bots apart. With the new API, a significant number of your valid human users will pass the reCAPTCHA challenge without having to solve a CAPTCHA. reCAPTCHA comes in the form of a widget that you can easily add to your blog, forum, registration form, etc.
Powered by machine learning
Hundreds of millions of CAPTCHAs are solved by people every day. reCAPTCHA makes positive use of this human effort by channeling the time spent solving CAPTCHAs into digitizing text, annotating images, building machine learning datasets. This in turn helps preserve books, improve maps, and solve hard AI problems.
Best link :
https://www.google.com/recaptcha/intro/invisible.html
Google recaptcha documenation :
https://developers.google.com/recaptcha/docs/verify
Demo link :
http://freeteachnology.hol.es/captcha/
Code link :
https://drive.google.com/file/d/0BxmTZPVcu72faGdZWDVqaGxoWlU/view?usp=drive_web
Create reCaptcha using following steps :
1-Go to link and create sitekey entering Site title,Site url,Owner name of site
Link : http://www.google.com/recaptcha/
2-after that click on getCaptcha key link,
3-register new website input label,reCapctah V2 select,enter domian name,check captcha term and condition,and click on register button ,
Following image show form of captcha registration :
select site key and screte key,
create following folder structure as :
1-header.php,
2-index.php,
3-footer.php,
4-action.php,
1-header.php :
Header.php file include bootstrap link and css and js file
Code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content='FreeTeachnology is a programming blog maintained by Disuza Jen. Tutorials focused on Programming, Jquery, Ajax, PHP, Demos, Web Design, Javascript, and MySQL.' name='description'/>
<meta content='java script, web development, web design, web programming, jquery ajax, ajax php, jquery ajax demos, jquery demos, regular expression, ajax demos, ajax programming, tutorials, php script, ajax tutorial, ajax examples, jquery tutorial, database, mysql, web database development, blogger, google ajax api, google visualization, google app, rss,API, technology, coding, code, examples, php programming, facebook scripts, twitter API, facebook like, twitter scripts, form validation, hosting, form submit, validation, free scripts, free hosting, sql script, programming, jsp, tomcat, SMTP Mail, Oauth, freeteachnology.blogsopt , freeteachnology, freeteachnology Programming' name='keywords'/>
<meta content='disuza jen' name='author'/>
<title>How to Integrate Google "reCAPTCHA" on Your Website</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.1.1.js" integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA=" crossorigin="anonymous"></script>
<link href="validation/error.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<!-- start:header -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid" id="freeteachnology">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="#">Free Teachnology</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home <span class="sr-only"></span></a></li>
<li><a href="#">About us</a></li>
<li><a href="#">Contact us</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
2-footer.php :
Footer link include validation link and social link :
Code :
<!-- Start::footer -->
<footer>
<div class="footer footer-bottom">
<div class="container">
<p class="pull-left"> Copyright © <?php echo date('Y');?>. Design and Develop by - Disuza Jen. </p>
<div class="pull-right">
<ul class="nav nav-pills payments">
<li>
<a target="blank" href="https://www.facebook.com/profile.php?id=100011576444095">
<i class="fa fa-facebook"></i></a>
</li>
<li>
<a target="blank" href="https://plus.google.com/116407769803493244155">
<i class="fa fa-google"></i></a>
</li>
<li>
<a target="blank" href="https://twitter.com/disuzajen1">
<i class="fa fa-twitter"></i></a></li>
<li>
<a target="blank" href="https://plus.google.com/116407769803493244155">
<i class="fa fa-link"></i>
</a>
</li>
</ul>
</div>
</div>
</div>
<!--/.footer-bottom-->
</footer>
<script src="validation/jquery.validate.js"></script>
<script src="validation/googlecaptcha.js"></script>
<!-- End::footer -->
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css">
</body>
</html>
3-index.php :
Index file show form of submit and simple code of recaptcha code which is placed in index.php files :
Captcha code :
Code :
<div class="g-recaptcha" data-sitekey="6Lfteh0UAAAAADMs-GVK2uZwJSFjelPbgUQfylYm"></div>
This div generated google and placed sitekey which is created.
Captcha js placed in header of index.php file :
Code :
<!-- Google recaptcha js link -->
<script src='https://www.google.com/recaptcha/api.js'></script>
<!-- Google recaptcha js link →
Captcha code value access using jquery :
Code :
Var captcha=$('#g-recaptcha-response').val();
And in php access value :
<?php
$captcha=$_POST[‘g-recaptcha-response'’];
?>
Following simple code of index.php files :
Code :
<?php include('header.php'); ?>
<body>
<div>
<br><br><br>
<?php
session_start();
if (!empty($_SESSION['statusMsg'])) {
echo '<p>' . $_SESSION['statusMsg'] . '</p>';
unset($_SESSION['statusMsg']);
}?>
<!-- Google recaptcha js link -->
<script src='https://www.google.com/recaptcha/api.js'></script>
<!-- Google recaptcha js link -->
<div class="cleafix"></div>
<div class="container">
<div class="alert alert-info">
<strong>Hi..</strong> How to Integrate Google "reCAPTCHA" on Your Website
</div>
<div class="alert alert-warning">
<a href="https://drive.google.com/open?id=0BxmTZPVcu72faGdZWDVqaGxoWlU" class="btn btn-xs btn-warning pull-right" target="blank();">Click</a>
<strong> Code download link-</strong>
</div>
<br><br>
</div>
<div class="clearfix"></div>
<div class="container">
<div class="panel-body">
<form action="" enctype="multipart/form-data" class="form-horizontal" id="googlecaptcha" name="googlecaptcha" method="post" >
<label id="shows"></label>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">First Name</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="fname" name="fname" placeholder="First name">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Last Name</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="lname" name="lname" placeholder="Last name">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Mobile</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="email" name="email" placeholder="Email ID">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Address</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="address" name="address" placeholder="Addess">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Captcha</label>
<div class="col-sm-6">
<div class="g-recaptcha" data-sitekey="6Lfteh0UAAAAADMs-GVK2uZwJSFjelPbgUQfylYm"></div>
<label id="captchMsg"></label>
</div>
</div>
<input type="hidden" name="action_type" value="add"/>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-primary" name="submit" id="submit" value="Submit"/>
<input type="reset" class="btn btn-default" value="Cancel" />
</div>
</div>
</form>
</div>
</div>
</div>
<?php include('footer.php'); ?>
If user can click on captcha link then captcha popup show as follow :
4-googlecaptcha.js :
Google captcha js file placed in validation folder,create code of jquery validation and form submit value post on action page ,
Code :
jQuery(document).ready(function () {
$("#googlecaptcha").validate({
rules: {
fname: {
required: true,
},
lname: {
required: true,
},
mobile: {
required: true,
number:true,
maxlength:10,
minlength:10
},
email:{
required: true,
email: true,
},
address: {
required: true,
},
},
messages: {
fname: {
required: "* Please enter first name.",
},
lname: {
required: "* Please enter last name.",
},
mobile: {
required: "* Please enter mobile no.",
number: "* Please enter only number.",
minlength: "* Mobile no should be minimum 10 digit.",
maxlength: "* Mobile no should be maximum 10 digit."
},
email:{
required: "* Please enter email.",
email:"* Enter email id is correct."
},
address: {
required: "* Please enter address.",
},
},
submitHandler : function(form) {
var fname = $.trim($('#fname').val());
var lname = $.trim($('#lname').val());
var mobile = $.trim($('#mobile').val());
var email = $.trim($('#email').val());
var address = $.trim($('#address').val());
var recaptcha = $.trim($('#g-recaptcha-response').val());
if(recaptcha=="")
{
$("#captchMsg").text("* Captcha is empty.").css("color","red");
}
$.ajax({
type: "POST",
url: "add-action.php",
async: true,
data: {fname:fname,lname:lname,mobile:mobile,email:email,address:address,recaptcha:recaptcha},
success: function(html) {
if(html==0) {
alert('Enter captcha correct value.');
} else if(html==1) {
alert('Form submited.');
}
}
});
}
});
});
5-add-action.php :
Action file value access which is form from in index.php files ,google captcha value access and store in one variable and validate captcha value following ways :
Code :
<?php
//start::capctch code
$secret = "6Lfteh0UAAAAAJBcWJoDuO0Bxw30E8dqPtFuNqp9";
$ip = $_SERVER['REMOTE_ADDR'];
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $catpctha);
//print_r($verifyResponse);
$responseData = json_decode($verifyResponse);
$responseData->success;
?>
Get response true and false
Full code of action files :
<?php
// echo '<pre>';
// print_r($_POST);
// die;
$submit = $_POST['submit'];
//Post data value::-
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$address = $_POST['address'];
$catpctha = (isset($_POST['recaptcha']) ? $_POST['recaptcha'] : '');
//start::capctch code
$secret = "6Lfteh0UAAAAAJBcWJoDuO0Bxw30E8dqPtFuNqp9";
$ip = $_SERVER['REMOTE_ADDR'];
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $catpctha);
//print_r($verifyResponse);
$responseData = json_decode($verifyResponse);
//End::capctch code
if ($responseData->success) {
echo '1';
exit();
}else {
echo '0';
exit();
}
?>
I hope that you can understand very well and refer my code thanks,if you like my code please share and comment,
Thanks
Comments