Simple class that implement a CAPTCHA for your PHP App.

Overview

simple-captcha

Simple class that implement a CAPTCHA for your PHP App.

GitHub GitHub release (latest SemVer)

Installation

Use the package manager composer to install.

composer require williamsampaio/simple-captcha

Documentation

1. Create new Captcha

 $captcha = new SimpleCaptcha();

If no parameters are passed the captcha code will be automatically generated with a length of 5 numeric characters.

But it is possible to pass two parameters. The first is a string with the captcha code (maximum length of 16 characters), the second is a boolean to generate random colors if true.

 $captcha = new SimpleCaptcha("H@ck3R'D_C0@r1", true);

2. Get the captcha code

 $captcha->getKey();

3. Get the captcha image

<img src="<?php echo $captcha->getImg() ?>" />

Example

A simple usage example.

<?php

require __DIR__ . '/../vendor/autoload.php';

use WilliamSampaio\SimpleCaptcha\SimpleCaptcha;

session_start();

$captcha = new SimpleCaptcha();

if(isset($_POST['captcha'])){

    if($_POST['captcha'] == $_SESSION['captcha']->getKey()){
        echo "<h1 style='color:green;'>Captcha valid! (".$_POST['captcha'] ."=". $_SESSION['captcha']->getKey().")</h1>";
    }else{
        echo "<h1 style='color:red;'>Captcha invalid! (".$_POST['captcha'] ."=". $_SESSION['captcha']->getKey().")</h1>";
    }

}

$_SESSION['captcha'] = $captcha;

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form method="post">
        <img src="<?= $captcha->getImg() ?>"/>
        <br>
        <input type="text" name="captcha" id="captcha">
        <hr>
        <input type="submit" value="Check">
    </form>
</body>
</html>
You might also like...
This Pocketmine-MP plugin lets you implement the ultimate birthday wishing system on your server.

BirthdaysPE This Pocketmine-MP plugin will let you wish player(s) a happy birthday and notify others to wish them too. Commands /birthday set/reset

A Simplistic Plugin to Implement Server Claims to your Minecraft: Bedrock Server.
A Simplistic Plugin to Implement Server Claims to your Minecraft: Bedrock Server.

Claims This plugin allows administrators to create, edit, list, and teleport to land claims on a PocketMine server. These claims have a variety of cus

YL MVC Structure (PHP MVC) is a pattern made in PHP used to implement user interfaces, data, and controlling logic.

YL MVC Structure (PHP MVC) is a pattern made in PHP used to implement user interfaces, data, and controlling logic. It is built based on the combination of ideas from the Yii framework and Laravel framework (yl).

The only way to implement the pipe operator in PHP.

Pipe Operator in PHP Introduction This package is based on the pipe operator RFC by Sara Golemon and Marcelo Camargo (2016), who explains the problem

A light-weight RPC implement of google protobuf RPC framework.

sofa-pbrpc A light-weight RPC implementation of Google's protobuf RPC framework. Wiki: https://github.com/baidu/sofa-pbrpc/wiki Features High performa

Implement event systems, signal slots, intercepting filters, and observers.

zend-eventmanager Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-eventmanager. zend-eventmanager is designed for the fol

This is an example app demonstrating how to deploy a php app to runway.

Runway Example php App This is an example app demonstrating how to deploy a php app to runway. clone this repo, and navigate into that directory runwa

HTMX example app that demonstrates how to use HTMX to add javascript interactivity to a serverside rendered PHP app

HTMX examle app This demo app demonstrates how to use HTMX to transform a server side rendered PHP app into a more 'interactive' app with AJAX request

A simple, standalone, modern PHP class inspector and mapper library, wrapping PHPs native reflection in a fluent interface

A simple, standalone, modern PHP class inspector and mapper library, wrapping PHPs native reflection in a fluent interface.

Releases(1.0.0)
Owner
WILLIAM B. SAMPAIO
WILLIAM B. SAMPAIO
Simple customizable captcha script for bot prevention in php language.

phpCaptcha Simple customizable captcha script for bot prevention in php language. Usage <?php session_start(); $status = ""; if ($_SESSION['captcha']

Филип Арсовски 11 Oct 10, 2022
Simple, image-based, mathematical captcha, with increasing levels of difficulty

simple-captcha Simple, image-based, mathematical captcha, with increasing levels of difficulty version 1.1.0 see also: ModelView a simple, fast, power

Nikos M. 6 Dec 18, 2022
Here are few exercises to practice how to implement API Security with NGINX App-Protect WAF.

api-security-lab This repo contains files for customers and partners to practice an API Security with NGINX App-Protect WAF. To demonstrate the capabi

null 4 Mar 30, 2022
dcat admin login captcha. - dcat admin 登录验证码。

dcat-login-captcha 简体中文 | ENGLISH dact admin login captcha. - dcat admin 登录验证码。 环境要求 dcat-admin >= 2.0 安装 Composer 安装 $ composer require guanguans/dca

guanguans 29 Dec 5, 2022
Friendly Captcha anti-spam plugin for Joomla!

Friendly Captcha anti-spam plugin for Joomla! Register at https://friendlycaptcha.com to get your site and secret keys. Plugin Features Standard light

null 10 Dec 14, 2022
WPBruiser {no- Captcha anti-Spam} (forked, updated)

=== WPBruiser {no- Captcha anti-Spam} === Contributors: mihche, knutsp Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_

Webfacing 2 Jul 26, 2022
It's a CodeIgniter Library for Captcha Generation. With additional Flexibility .

Original Source : Pavel Tzonkov <[email protected]> Source Link : http://gscripts.net/free-php-scripts/Anti_Spam_Scripts/Image_Validator/d

Chris # 4 Sep 2, 2022
a simple pastebin implement in php

alcohol/pastebin-php I mostly use this demo application to keep myself up to date with the various changes introduced by new (major) Symfony releases.

Rob 26 Nov 5, 2022
Provides simple interfaces to implement a webhook-based tweeting system

webhook-tweeter This package aims to provide simple interfaces to implement a webhook-based tweeting system. This can, for example, be used to tweet a

Ricardo Boss 2 May 7, 2022
Exploiting and fixing security vulnerabilities of an old version of E-Class. Project implemented as part of the class YS13 Cyber-Security.

Open eClass 2.3 Development of XSS, CSRF, SQLi, RFI attacks/defences of an older,vulnerable version of eclass. Project implemented as part of the clas

Aristi_Papastavrou 11 Apr 23, 2022