PHPackages                             av-lib/age-verification - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. av-lib/age-verification

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

av-lib/age-verification
=======================

Verify visitors age (ID/face scan/etc) in geographical regions that require it with multiple providers.

v1.2.0(6mo ago)10MITPHP

Since Nov 13Pushed 6mo agoCompare

[ Source](https://github.com/av-lib/age-verification)[ Packagist](https://packagist.org/packages/av-lib/age-verification)[ RSS](/packages/av-lib-age-verification/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (6)Used By (0)

Summary: Verify visitors age (ID/face scan/etc) in geographical regions that require it with multiple providers.

[![Packagist Version](https://camo.githubusercontent.com/352819ce82f905606d18f14aa040d199b0b70cbc93563d0012f584d17fb28102/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61762d6c69622f6167652d766572696669636174696f6e)](https://packagist.org/packages/av-lib/age-verification)[![Packagist Downloads](https://camo.githubusercontent.com/7e7a0b0db932374f5e0716f2a2d76c51333824749a4b042213d540296b4644d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61762d6c69622f6167652d766572696669636174696f6e)](https://packagist.org/packages/av-lib/age-verification)[![Packagist License](https://camo.githubusercontent.com/6b128d65c16c5b453172e1786fcb93d78ff889003175c1a6c088df31817ba2ea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f61762d6c69622f6167652d766572696669636174696f6e)](https://camo.githubusercontent.com/6b128d65c16c5b453172e1786fcb93d78ff889003175c1a6c088df31817ba2ea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f61762d6c69622f6167652d766572696669636174696f6e)

Age Verification Library for PHP
================================

[](#age-verification-library-for-php)

This project includes a set of PHP scripts that may be useful for PHP websites integrating age verification checks. It may be useful to sites that contain adult content that are now potentially required to verify user age under state law. It is intended to be primarily a server-side (PHP) solution as opposed to a client-side (JavaScript) solution.

While it is still a fair bit of effort to integrate age verification into a website, the hope with this library is that it may be faster than starting from scratch.

This library is flexible, you can override any functions you need to. You can add your own custom providers, or even use it with no providers and only use the region-blocking portion of it.

Supported Providers
-------------------

[](#supported-providers)

ProviderID Scan (full)ID Scan (redacted)Facial Age EstimationCredit CardE-mailCost[Redact-ID](https://redact-id.com)✅✅$20/mo+ ($0.05/verif)[Go.Cam](https://go.cam)✅✅✅ (But not FR, DE, US, GB)✅FreeYou may send a pull request for your preferred provider if it fits within the existing technical design of this library and can be licensed under MIT. If it is large or requires unusual dependencies, it could be added via a separate repo via a plugin architecture.

Features
--------

[](#features)

- Validation of user age through multiple providers.
- Your account system does not need to be aware of the particulars of specific provider's logic, so you can change providers or add providers easily later.
- Extensible, so you can configure other methods that trigger the validation (ex: flag as 18+ after your own credit card checks, etc.)
- Support for storing age verification status both for registered users (with account) and guest users (without account). Guest user validation is remembered via a server-verifiable cookie.
- Can skip age checks for search engine bot traffic so your site does not have trouble with search engines.
- Can perform age checks in only specific regions that require it, or everywhere, or whatever your preference is. You choose the territories. Defaults based on US states that require age verification for 18+ content.
- Cron script to download GeoLite database, test it, and install it automatically. It will also trigger an alert if the database has gone stale.
- Memcache support to reduce unnecessary database access.

Example Screenshot
------------------

[](#example-screenshot)

The library fits into your existing site theming, but here's an example of it in use:

[![Screenshot](screenshot.png)](screenshot.png)

Your page will end up looking different, as the library itself does not dictate or include any particular UI.

Requirements
------------

[](#requirements)

- Tested on PHP 8.3.6 on Linux, may work in other environments also.
- Tested on MySQL server 8 for database storage.
- PHP extensions for MySQL PDO and memcache.
- Memcache server for memory caching

Instructions for Use
--------------------

[](#instructions-for-use)

1. Register with one or multiple of the supported providers.

    a. Configuration note for Redact-ID, your "Verification Link" should be set to something like `https://your-site.example.com/ageBlock.php?provider=RedactID&linkback` (You can customize this file name in step 5)
2. [Install via composer](https://packagist.org/packages/av-lib/age-verification): `composer require av-lib/age-verification`
3. Create your own implementation class of AgeVerification, using XXX as an example. The library is designed to be subclassed, so if a particular method does not work for your site, you can override it as needed. For instance,

    - It is suggested you check which territories you are required to verify age and override that function if it is not the same as the main class provides for you.
    - Provide PDO &amp; Memcache access by overriding the relevant function.
4. Database: In your accounts table, create new fields for an `ageVerified` enum and `redactIdReference`:

```
ALTER TABLE `accounts` ADD `ageVerified` ENUM('REDACT-ID','GOCAM','COOKIE') NULL;
ALTER TABLE `accounts` ADD `verificationReference` VARCHAR(255) NULL AFTER `ageVerified`;
```

Having a not-null value for `ageVerified` will flag the account as having undergone age verification. ID Providers can optionally store some data into the `verificationReference` field, for instance, a hash to show that verification was performed.

5. Also create a new table to store ageTokens. These are used by guest users to remember that they have gone through age verification:

```
-- Table Structure
CREATE TABLE `ageTokens` (
  `tokenID` bigint NOT NULL,
  `token` char(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `issued` datetime NOT NULL,
  `verified` tinyint(1) NOT NULL DEFAULT '0'
);

-- Indexes
ALTER TABLE `ageTokens`
  ADD PRIMARY KEY (`tokenID`),
  ADD UNIQUE KEY `token_index` (`token`) USING BTREE;

-- Auto Increment
ALTER TABLE `ageTokens`
  MODIFY `tokenID` bigint NOT NULL AUTO_INCREMENT;
COMMIT;
```

6. Create an ageBlock.php page that users are re-directed to when they are to be blocked due to age verification requirement. See XXX for example. It should check if the user is blocked, and if so, include links for each provider you are using. This page will also serve as the point for receiving callback events. It does not have to be named ageBlock.php, you can name it something else as long as you update the relevant function.
7. On every page that a user should be age checked, call the `redirectToAgeVerificationIfShould()` function. This should happen before page output is done, but can happen after session is started.

```
AgeVerificationMySite::instance()->redirectToAgeVerificationIfShould();
```

8. Setup the geographical database `downloadTestAndInstall.php` database script:

    - You can configure it to use the official download location or a github mirror, depending on your preferences.
    - Modify the script to point to your own Health Checks URL (or comment it out if you don't want alerts, but that is not recommended).
    - Set up a cron to run the GeoLite every other day.
    - Run the script once so the database will be available.
9. A user might choose to age verify as a guest *before* they register. Thus, you should upgrade the account to age verified status at certain key points if they have a valid guest age verification token. These points are likely check points:

    - Login via login form
    - Login via cookie
    - Registration

Example:

```
// If account was not previouly age verified, but has the age verification guest token, set their
// account appropriately.
if (AgeVerificationMySite::instance()->getAgeVerifiedAccount($accountID) == false &&
	isset($_COOKIE["ageVerificationToken"]) &&
	AgeVerificationMySite::instance()->checkAgeVerificationToken($_COOKIE["ageVerificationToken"]) === true)
{
	AgeVerificationMySite::instance()->setAgeVerifiedAccount($accountID, "COOKIE"); // Upgrades account to age verified status
}
```

10. Test thoroughly. You can force age verification checking on your localhost testing by overriding `ipInRestrictedTerritory()` to always return true. You can simulate a successful verification by uncommenting the `test-force` in the example `ageBlock.php` page. Remember that to reset after a test, you need to change the database account fields back, as well as flush memcache, as well as delete the relevant cookies.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance69

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~0 days

Total

5

Last Release

182d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/91b3f73c2423bd3d07b116bf12443d9119d57bbfc68f319c9006b45cfe40cc4c?d=identicon)[av-lib](/maintainers/av-lib)

---

Top Contributors

[![av-lib-git](https://avatars.githubusercontent.com/u/243691783?v=4)](https://github.com/av-lib-git "av-lib-git (10 commits)")

### Embed Badge

![Health badge](/badges/av-lib-age-verification/health.svg)

```
[![Health](https://phpackages.com/badges/av-lib-age-verification/health.svg)](https://phpackages.com/packages/av-lib-age-verification)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[aporat/store-receipt-validator

PHP receipt validator for Apple App Store and Amazon Appstore

6503.9M9](/packages/aporat-store-receipt-validator)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[scheb/2fa

Two-factor authentication for Symfony applications (please use scheb/2fa-bundle to install)

578630.7k1](/packages/scheb-2fa)

PHPackages © 2026

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