Code Monkey home page Code Monkey logo

gd-captcha's Introduction

GD-captcha

This repository can easily make a captcha image for you and take control of checking its accuracy.

Attributes

  • Random color with each reload
  • Random word types (letter&number, just letter , just number) depends on your luck ^_~
  • Random text color (black or white)

Used items

  • Definitely PHP >= v7.4 ;)
  • GD library

How to use

  1. Add Captcha.php and captcha_add.php to your current directory.
  2. include Captcha.php to your main file
  3. If GD library is not already active for you, just uncomment ;extension=php_gd2.dll By removing ; behind it from php.ini.
  4. Follow the steps below

According to demo.php, we assume you have a form in the page:

<form class="mx-auto" method="post">
   <div class="form-group">
      <label for="exampleInputEmail1">Email address</label>
      <input type="email" class="form-control" name="email" placeholder="Enter email">
   </div>
   <div class="form-group">
      <label for="exampleInputPassword1">Password</label>
      <input type="password" class="form-control" name="password" placeholder="Password">
   </div>
   <div class="form-group ">
      <label for="exampleInputPassword1">Enter the Captcha</label>
      <div class="d-flex">
         <input type="text" class="form-control mr-2" name="captcha" placeholder="captcha">
         <img src="captcha_add.php" alt="">
      </div>
   </div>
   <button type="submit" class="btn btn-primary" name="submit">Submit</button>
</form>

As you see, I put an image tag with captcha_add.php src where the image is output.

You can have something like this:

captcha

Personalization options

  • Image width
  • Image height
  • String font size (optional)
  • String length (optional)
  • String font family (optional)

You can set these options in captcha_add.php e.g.

$captcha = new Captcha();
$captcha->captchaControl(200,50,null,5,"Sriracha-Regular.ttf");

If you don't want to set a parameter leave it with null value and let it be the default one.

About font file that is the last parameter, you have two choices.

  1. URL (As the default value) e.g. https://fonts.gstatic.com/s/acme/v17/RrQfboBx-C5_bx0.ttf
  2. A font file name in the current directory

Final step

When you want to check the accuracy of the entered value you can use a static method called checkCaptcha. e.g.

<?php

if (isset($_POST['submit'])){
    if (Captcha::checkCaptcha($_POST['captcha'])){
        echo "Correct value";
    }else{
        echo "Wrong value entered!";
    }
}
 ?>

Author

gd-captcha's People

Contributors

atenadadkhah avatar

Stargazers

 avatar  avatar

Watchers

 avatar

gd-captcha's Issues

Is this repository helpful?

I noticed that some times web developers don't want to use reCaptcha, instead they want to use a good captcha. So I wrote an object-oriented captcha that could be easily used.
Is there any way to improve it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.