Google reCAPTCHA is a new kind of captcha system introduced to increase form security and prevent spamming completely you can easily add Google reCAPTCHA to your website.
In this tutorial we will show you how to create signup form with google recaptcha using PHP and MySQL.
You may also like captcha system on signup using PHP.
To Create Signup Form With Google reCAPTCHA It Takes Only Three Steps:-
- Register your website and get all details
- Make a HTML file and define markup for signup form
- Make a PHP file to check captcha and store details
Step 1. Register your website and get all details
To add google recaptcha to your website you need to register your website here https://www.google.com/recaptcha/admin. Then get your site key and secret key.
Step 2. Make a HTML file and define markup for signup form
We make a HTML file and save it with a name signup.html
<html> <head> <script src="https://www.google.com/recaptcha/api.js" async defer></script> </head> <body> <div id="wrapper"> <form action="do_signup.php" method="POST"> <input type="text" name="name" value=""/> <input type="text" name="email" value=""/> <input type="password" name="password"/> <div class="g-recaptcha" data-sitekey="Your Site Key"></div> <input type="submit" name="submit" value="SUBMIT"> </form> </div> </body> </html>
In this step we create a form for user signup and add Google reCAPTCHA div in our form just place your site key in 'data-sitekey' and we also add api.js javascript file for captcha given by google.
Step 3. Make a PHP file to check captcha and store details
We make a PHP file and save it with a name do_signup.php
// Database Structure CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` text NOT NULL, `email` text NOT NULL, `password` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1 <?php if(isset($_POST['submit']) && $_POST['g-recaptcha-response']!="") { $secret = 'You Site Key'; $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']); $responseData = json_decode($verifyResponse); if($responseData->success) { $name = $_POST['name']; $email = $_POST['email']; $pass = $_POST['password']; $host="localhost"; $username="root"; $password=""; $databasename="sample"; $connect=mysql_connect($host,$username,$password); $db=mysql_select_db($databasename); mysql_query("insert into users values('','$name','$email','$pass')"); echo "Successfully Signup"; } }
In this step we create a table called 'users' to store users data after signup then check the captcha using google link by passing site key and captcha and if the entered captcha is correct we store the user details in our database.
You may also like login with google using PHP.
Thats all, this is how to create signup form with google reCAPTCHA using PHP and MySQL. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.
Latest Tutorials
- Create Animated Skill Bar Using jQuery, HTML And CSS
- Simple And Best Responsive Web Design Using CSS Part 2
- Show Button On Hover Using HTML And CSS
- Material Design Login Form Using jQuery And CSS
- Animated Progress Bar Using jQuery And CSS
- Dynamic Drop Down Menu Using jQuery, Ajax, PHP And MySQL
- Get Website Statistics Using PHP, jQuery And MySQL
- HTML5 Login And Signup Form With Animation Using jQuery
- Facebook Style Homepage Design Using HTML And CSS
- View Webpage In Fullscreen Using jQuery