Devnote

Web Development Blog Company, Services India

MySQL Error 121 Duplicate key on write - Practical Repair Strategy
MySQL Error 121 Duplicate key on write – Practical Repair Strategy
February 13, 2026
PHP cURL error 60: SSL certificate problem - Windows & Linux Fix
PHP cURL error 60: SSL certificate problem – Windows & Linux Fix
February 11, 2026
Fix localhost refused to connect After Installing XAMPP / WAMP
Fix “localhost refused to connect” After Installing XAMPP / WAMP
February 9, 2026
Composer Error Memory exhausted When Installing Packages - Real Fix
Composer Error: Memory exhausted When Installing Packages – Real Fix
February 6, 2026
MySQL 8 Error Unknown collation: utf8mb4_0900_ai_ci - Safe Migration Guide
MySQL 8 Error Unknown collation: utf8mb4_0900_ai_ci – Safe Migration Guide
February 4, 2026
Devnote

Type and hit Enter to search

  • Home
  • Laravel
    • Auth
    • Migration
    • DATATABLE
    • Yajra
  • wordpress
    • plugin
    • WPBakery
    • woocommerce
  • PHP
    • MYSQL
    • Ajax
  • Blog
  • Informational
    • About us
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
  • Contact US
Devnote
  • Home
  • Laravel
    • Auth
    • Migration
    • DATATABLE
    • Yajra
  • wordpress
    • plugin
    • WPBakery
    • woocommerce
  • PHP
    • MYSQL
    • Ajax
  • Blog
  • Informational
    • About us
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
  • Contact US
Image

Create a Simple Captcha Code in PHP

Image
Devnote team
February 10, 2025
One Min Read
2.5K Views
0 Comments

This tutorial is for Create a Simple Captcha Code in PHP. This is the best way and very simple to build captcha code in PHP. Captcha most commonly uses your site if another person is not scraping or for other reasons depending on your requirement. In this example, I have displayed an image in captcha code.

In this tutorial, we will generate a unique CAPTCHA every time, a random number is generated using the rand() function in PHP which generates a random number between 0 to 61 and substr to get only 6 digits.

Create a Simple Captcha Code in PHP is allowing users to enter data into our website, and we need to check entered by the human. Otherwise, people will use robots to push the bulk and add dummy data into the website.

In this tutorial, we will use the PHP GD library to create our CAPTCHA. We will also have to write a little bit of code and create a random string to be written on the image.

#images.php

<?php session_start();
   
    $images = imagecreate(110,60);
   
    $green = imagecolorallocate($images,0,200,0);
    $gray = imagecolorallocate($images,230,230,230);
   
    imagefill($images,0,0,$gray);
   
    $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
   
    $var= "";
   
    for($i=1;$i<=6;$i++) { 
        $var = $var.substr($str,rand(0,61),1);
    }
   
    $_SESSION['capital'] = $var;
   
    imagettftext($images,20,0,9,29,$green,$var);
   
    header("content-type:image/jpeg");
   
    imagejpeg($images);
      
    imagedestroy($images);
?>
#index.php
<img src="images.php" alt="images">

Categories:

PHP

Other Articles

Laravel: Remove All Spaces from a String with Examples
Previous

Laravel: Remove All Spaces from a String with Examples

laravel passport api
Next

How to integrate passport API in Laravel

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

PHP cURL error 60: SSL certificate problem - Windows & Linux Fix

PHP cURL error 60: SSL certificate problem – Windows & Linux Fix

February 11, 2026
PHP 8.3 Fatal Error: Cannot use string offset as an array - Real World Case

PHP 8.3 Fatal Error: Cannot use string offset as an array – Real World Case

January 30, 2026
Image

How to Fix Nginx 413 Request Entity Too Large for Image & Video Uploads

January 28, 2026
PHP file_put_contents(): Failed to open stream in Storage and Cache - Permissions Fix Guide

PHP file_put_contents(): Failed to open stream in Storage and Cache – Permissions Fix Guide

January 14, 2026
Devnote

Devnote provides a collection of tutorials about PHP, Laravel, WordPress, Django, MySQL, Bootstrap, Jquery, Ajax, APIs, CRUD operations, etc.

Devnote © , All Rights Reserved.

Page Links

  • Home
  • About us
  • Blog
  • Contact US
  • Site map

Category

  • PHP
  • Laravel
  • wordpress
  • HTML
  • jQuery

Follow Us

Facebook Instagram Twitter Youtube Linkedin Pinterest
Morbi, Gujarat, India - 363641
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT
Advertisement
Advertisement