Code Monkey home page Code Monkey logo

captcha's Introduction

Captcha

It's simply an old-school captcha app.

php-basic-captcha

Requirements

  • PHP 5.6 or higher
  • PHP GD Extension

Installation

composer require muhammetsafak/captcha:dev-main

or download and include the file src/Captcha.php.

Usage

The file src/image-captcha.php simply generates and presents a captcha for you. You can edit this file for a custom configuration or create your own.

Configuration

$configs = array(
    'width'         => 200, // Width of captcha image to be created
    'height'        => 70, // Height of captcha image to be created
    'length'        => 7, // The number of characters to be found in the captcha image.
    'font'          => __DIR__ . '/src/AHGBold.ttf', // Defines the font of the captcha characters.
    'size'          => 18 // Defines the size of captcha characters.
);

To create a captcha image; image-captcha.php

require_once __DIR__ . '/src/Captcha.php';
$config = array(
    'width'         => 180,
    'height'        => 50,
    'length'        => 6
);
$captcha = new \MuhammetSafak\Captcha\Captcha($config);
$captcha->create();
<form method="POST">
    <input type="text" name="your_name" placeholder="Your Name"/><br />
    
    <img src="src/image-captcha.php" id="captcha" /> <br />
    <button onclick="captcha_refresh()">Refresh</button>
    <input type="text" name="areYouBot" placeholder="Captcha" /><br />
    
    <input type="submit" value="Gönder" />
</form>
<script>
    function captcha_refresh()
    {
        img = document.getElementById("captcha");
        img.src = '../src/image-captcha.php';
    }
</script>

A simple validation example is as follows.

require_once __DIR__ . '/src/Captcha.php';
$captcha = new \MuhammetSafak\Captcha\Captcha();
if(isset($_POST)){
    if($captcha->verify($_POST['areYouBot'])){
        // Success
        // ...process
    }else{
        // Error
        echo 'Enter the characters in the picture correctly.';
    }
}

Licence

Copyright © 2022 MIT License

captcha's People

Contributors

muhammetsafak avatar

Watchers

 avatar

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.