Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
    • Guest Posting Service
  • Advertise
  • About
  • Contact Us

How to Add Captcha in PHP Registration Form?

March 10, 2021 Pakainfo php, Ajax, JavaScript, jQuery Leave a comment

Today, We want to share with you how to add captcha in php registration form.In this post we will show you how to validate captcha in php, hear for how to add google captcha in php registration form we will give you demo and example for implement.In this post, we will learn about Simple PHP Create Custom Captcha Generator with an example.

Implementation of Captcha in Registration Form in PHP

Contents

  • Implementation of Captcha in Registration Form in PHP
    • Related posts

Step 1: Create Table In DB by Sql Query

CREATE TABLE `visitors1` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(30) NOT NULL,
  `email` varchar(100) NOT NULL,
  `password` varchar(250) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Step 2: Create a Database Connection PHP File

<?php
    $servername='localhost';
    $username='root';
    $password='';
    $dbname = "pakainfo_demo";
    $conn=mysqli_connect($servername,$username,$password,"$dbname");
      if(!$conn){
          die('Could not Connect MySql Server:' .mysql_error());
        }
?>

Step 3: Register your website on Google Re captcha and Get All Details

To add google recaptcha to your website you need to register your website here Google captcha Link: https://www.google.com/recaptcha/admin .Then get your site key and secret key.about:blank

Step 4: Create User Registration Form with Captcha Validation In PHP

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>How to Add Captchacode in PHP Registration Form</title>
        <!-- CSS -->
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
        <script src="https://www.google.com/recaptcha/api.js" async defer></script>
    </head>
<body>
<div class="container mt-5">
    <div class="card">
        <div class="card-header text-center">
            Add Google Captchacode in PHP Registration Form
        </div>
        <div class="card-body">
            <form action="validate-captcha.php" method="post">
                <div class="form-group">
                    <label for="simpleDemoWithFun">Name</label>
                    <input type="text" name="name" class="form-control" id="name" required="">
                </div>                                
                <div class="form-group">
                    <label for="simpleDemoWithFun">Email location</label>
                    <input type="email" name="email" class="form-control" id="email" aria-describedby="emailHelp" required="">
                    <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
                </div>
                <div class="form-group">
                    <label for="simpleDemoWithFun">Password</label>
                    <input type="password" name="password" class="form-control" id="password" required="">
                </div>                   
                <div class="form-group">
                    <label for="simpleDemoWithFun">Confirm Password</label>
                    <input type="password" name="cpassword" class="form-control" id="cpassword" required="">
                </div>   
                <div class="g-recaptcha" data-sitekey="Your Site Key"></div>
                <input type="submit" name="password-reset-token" class="btn btn-primary">
            </form>
        </div>
    </div>
</div>
</body>
</html>

Step 5: Create PHP File to Check Captchacode and Save User Details

<?php
if(isset($_POST['submit']) && $_POST['g-recaptcha-response']!="")
{
    include "db.php";
    $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'];
        mysqli_query($conn, "INSERT INTO visitors(name, email ,password) VALUES('" . $_POST['name'] . "', '" . $_POST['email'] . "', '" . md5($_POST['password']) . "')");
        echo "Visitor registration form with captchacode validation has been successfully saved";
    }
}

I hope you get an idea about how to add captchacode in php login form.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related posts:

  1. how to add captcha in php registration form?
  2. how to add captcha in login form in codeigniter?
  3. how to implement custom captcha code in php Script?
Also Read This 👉   jquery Increment Animating Numbers Counting Up Example
captcha code in php with javascript validationcheck captcha before submit in phphow to add captcha in core phphow to add captcha in login form in htmlhow to add captcha in php login formhow to add google captcha in php registration formhow to validate captcha in phplogin form with captcha php

Post navigation

Previous Post:Paypal Payment Gateway Integration in PHP Codeigniter Example
Next Post:Bootstrap 4 Testimonials or People Review Slider

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (64) Ajax (464) AngularJS (377) ASP.NET (61) Bio (109) Bollywood (108) Codeigniter (175) CSS (98) Earn Money (93) Education (63) Entertainment (130) fullform (87) Google Adsense (64) Highcharts (77) History (40) Hollywood (109) JavaScript (1359) Jobs (42) jQuery (1423) Laravel (1088) LifeStyle (53) movierulz4 (63) Mysql (1035) Mysqli (894) php (2133) Programming (2345) Python (99) Software (178) Software (90) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (147) Technology (2416) Tips and Tricks (130) Tools (214) Top10 (506) Trading (95) Trending (76) VueJs (250) Web Technology (113) webtools (200) wordpress (166) World (343)

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Info Grepper
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

© 2023 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype Guest Posting Sites