Need a Website Or Web Application Or Any Help In Code , Contact Us: +91 9437911966 (Whatsapp), Note: Paid Service
Students Tutorial app relased. Download Now.

How to add captcha in PHP form

PHP CAPTCHA is used to prevent robots from entering data. It makes the form more secure.

In this example we used two file.

  1. index.php
  2. captcha.php


	if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='')  {
        echo "<script>alert('Incorrect verification code');</script>" ;
		echo "<script>alert('Verification code match !');</script>" ;
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap Elegant Account Login Form with Avatar Icon</title>
<link rel="stylesheet" href="">
<link href="|Varela+Round" rel="stylesheet">
<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>
<div class="login-form">    
    <form action="" method="post">
		<div class="avatar"><i class="material-icons"></i></div>
    	<h4 class="modal-title">Login to Your Account</h4>
        <div class="form-group">
            <input type="text" class="form-control" placeholder="Username" required="required">
        <div class="form-group">
            <input type="password" class="form-control" placeholder="Password" required="required">
		<div class="form-group">
            <input type="text" name="vercode" class="form-control" placeholder="Verfication Code" required="required">
        <div class="form-group small clearfix">
            <label class="checkbox-inline">Verification Code</label>
              <img src="captcha.php" >
        <input type="submit" class="btn btn-primary btn-block btn-lg" value="Login">              


	$text = rand(10000,99999); 
	$_SESSION["vercode"] = $text; 
	$height = 25; 
	$width = 65;   
	$image_p = imagecreate($width, $height); 
	$black = imagecolorallocate($image_p, 0, 0, 0); 
	$white = imagecolorallocate($image_p, 255, 255, 255); 
	$font_size = 14; 
	imagestring($image_p, $font_size, 5, 5, $text, $white); 
	imagejpeg($image_p, null, 80);