PHPackages                             zexbre/mathguard - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. zexbre/mathguard

ActiveLibrary

zexbre/mathguard
================

Generate mathematical expression, which can be used as anti-spam solution.

v3.1.1(4y ago)16PHP

Since Oct 16Pushed 4y ago1 watchersCompare

[ Source](https://github.com/zexbre/mathguard)[ Packagist](https://packagist.org/packages/zexbre/mathguard)[ Docs](https://www.codegravity.com/projects/mathguard)[ RSS](/packages/zexbre-mathguard/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (2)Used By (0)

ZexBre\\MathGuard
=================

[](#zexbremathguard)

MathGuard form antispam protection version 3.1
----------------------------------------------

[](#mathguard-form-antispam-protection-version-31)

Creating this website I attracted lots of spambots to flood my forum, my programming resources, freelance database and other forms, but you probably know this situation very well. So I decided to create a simple PHP Class which could help me and probably other people to deal with the spam.

[![](img/mathguard301.gif)](img/mathguard301.gif)

You have probably seen this solution before on some other websites, it's nothing new, but I did it by myself and the way I wanted and I am using it everywhere it's needed.

### The principle of this antispam class

[](#the-principle-of-this-antispam-class)

The principle is very simple - The class inserts a small piece of HTML code into your form - an expression consisting of two random numbers, one text input field for user's answer, and one hidden field with the hashcode.

When user submits the form with the answer, the answer is being hashed and compared to the security code that has been submitted as well.

### How to set up this PHP antispam class and use it on your website?

[](#how-to-set-up-this-php-antispam-class-and-use-it-on-your-website)

#### 1. Download the code of MathGuard

[](#1-download-the-code-of-mathguard)

Go to the [download section](https://www.codegravity.com/download/) on this website and find there the **mathguard.zip**.

#### 2. Unzip the archive and copy the

[](#2-unzip-the-archive-and-copy-the)

#### 3. Open the code with the form you want to protect

[](#3-open-the-code-with-the-form-you-want-to-protect)

#### 4. Add the following code snippet (the one in the ellipse)

[](#4-add-the-following-code-snippet-the-one-in-the-ellipse)

[![](img/mathguard02.gif)](img/mathguard02.gif)

#### 5. Protect the form handler

[](#5-protect-the-form-handler)

[![](img/mathguard03.gif)](img/mathguard03.gif)

```
/* first we need to require our MathGuard class */
namespace ZexBre\MathGuard\MathGuard;

/* this condition checks the user input. Don't change the condition, just the body within the curly braces */
if (MathGuard :: checkResult($_REQUEST['mathguard_answer'], $_REQUEST['mathguard_code'])) {
    echo ("Great !"); //insert your code that will be executed when user enters the correct answer
} else {
    echo ("Bad answer, go back to school !");	//insert your code which tells the user he is spamming your website
}
```

#### 6. Open the form in your browser and you should see the mathguard's security question there

[](#6-open-the-form-in-your-browser-and-you-should-see-the-mathguards-security-question-there)

#### 7. Example

[](#7-example)

There is also an example in the mathguard.zip. It features a simple form and one simple form handler which displays the data.

#### 8. Enjoy !

[](#8-enjoy-)

If you'd have any questions, feel free to write to the comments or directly to my email.

[CodeGravity.com](https://www.CodeGravity.com)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1675d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dcd12d70fb4994a934f3263c3be43034a76b8c8375f983402d8cb0b5c1d24f05?d=identicon)[niks986](/maintainers/niks986)

---

Tags

spamspam-detectionspam-filterspam-filteringspam-formspam-preventionspam-protection

### Embed Badge

![Health badge](/badges/zexbre-mathguard/health.svg)

```
[![Health](https://phpackages.com/badges/zexbre-mathguard/health.svg)](https://phpackages.com/packages/zexbre-mathguard)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
