kmlpandey77 / math-captcha
A Simple PHP Math Captcha
1.0.2
2023-04-05 17:22 UTC
This package is auto-updated.
Last update: 2025-04-08 06:56:16 UTC
README
A Simple PHP Math Captcha
Preview
Math in Image
Math in Text
Usage
composer require kmlpandey77/math-captcha
Math in Image
It will return Math in image
Create captcha.php
<?php require_once 'vendor/autoload.php'; // link to vendor's autoload.php use Kmlpandey77\MathCaptcha\Captcha; $captcha = new Captcha(); $captcha->image();
Create form.php
<form action="check.php" method="post"> <p> Answer it <img src="./captcha.php" alt="" valign="middle"> <input type="text" name="captcha"> </p> <p><button type="submit" name="submit">Submit</button></p> </form>
Math in Text
It will return Math in text
Create form.php
Place this code to top of form.php
<?php require_once 'vendor/autoload.php'; // link to vendor's autoload.php use Kmlpandey77\MathCaptcha\Captcha; ?>
And place this code in body
<form action="check.php" method="post"> <p> Answer it <?php echo new Captcha; ?> <input type="text" name="captcha"> </p> <p><button type="submit" name="submit">Submit</button></p> </form>
Check
Checks to see if the user entered the correct captcha key
Create check.php
<?php require_once 'vendor/autoload.php'; // link to vendor's autoload.php use Kmlpandey77\MathCaptcha\Captcha; if(isset($_POST['submit'])){ if(Captcha::check()){ //valid action echo('<font color="green">Answer is valid</font>'); }else{ echo('<font color="red">Answer is invalid</font>'); } }