PHPackages                             universetech-inc/hashids - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. universetech-inc/hashids

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

universetech-inc/hashids
========================

Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers

v0.1.1(2y ago)013MITPHPPHP ^8.1

Since May 30Pushed 3mo agoCompare

[ Source](https://github.com/universetech-inc/hashids)[ Packagist](https://packagist.org/packages/universetech-inc/hashids)[ Docs](https://hashids.org/php)[ RSS](/packages/universetech-inc-hashids/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (6)Used By (0)

[![hashids](https://camo.githubusercontent.com/c18b3677d02769b80412ab8398f7363896ce557caeac8453ee8249cd68b2c6d1/68747470733a2f2f686173686964732e6f72672f7075626c69632f696d672f686173686964732e676966 "Hashids")](https://hashids.org/)

[![Build Status](https://camo.githubusercontent.com/6efdf203ba0f8378cc2453df525837f714c96f71e9e6588713296abfadc5ead7/68747470733a2f2f62616467656e2e6e65742f6769746875622f636865636b732f76696e6b6c612f686173686964733f6c6162656c3d6275696c642669636f6e3d676974687562)](https://github.com/vinkla/hashids/actions)[![Monthly Downloads](https://camo.githubusercontent.com/fb34d1cd660b022a122b30f006da2cf4efd90c057be336cdc6d5c2e701688ac8/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f646d2f686173686964732f68617368696473)](https://packagist.org/packages/hashids/hashids/stats)[![Latest Version](https://camo.githubusercontent.com/8e6f5aa3d339dd83f6ef6c4a7434abd804a998f283995f26ef6524010433d5cd/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f686173686964732f68617368696473)](https://packagist.org/packages/hashids/hashids)

**Hashids** is a small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database numeric ids to users:

Getting started
---------------

[](#getting-started)

Require this package, with [Composer](https://getcomposer.org), in the root directory of your project.

```
composer require hashids/hashids
```

Then you can import the class into your application:

```
use Hashids\Hashids;

$hashids = new Hashids();

$hashids->encode(1);
```

> **Note** Hashids require either [`bcmath`](https://secure.php.net/manual/en/book.bc.php) or [`gmp`](https://secure.php.net/manual/en/book.gmp.php) extension in order to work.

Quick Example
-------------

[](#quick-example)

```
use Hashids\Hashids;

$hashids = new Hashids();

$id = $hashids->encode(1, 2, 3); // o2fXhV
$numbers = $hashids->decode($id); // [1, 2, 3]
```

More Options
------------

[](#more-options)

#### A few more ways to pass input ids to the `encode()` function:

[](#a-few-more-ways-to-pass-input-ids-to-the-encode-function)

```
use Hashids\Hashids;

$hashids = new Hashids();

$hashids->encode(1, 2, 3); // o2fXhV
$hashids->encode([1, 2, 3]); // o2fXhV
$hashids->encode('1', '2', '3'); // o2fXhV
$hashids->encode(['1', '2', '3']); // o2fXhV
```

#### Making your output ids unique

[](#making-your-output-ids-unique)

Pass a project name to make your output ids unique:

```
use Hashids\Hashids;

$hashids = new Hashids('My Project');
$hashids->encode(1, 2, 3); // Z4UrtW

$hashids = new Hashids('My Other Project');
$hashids->encode(1, 2, 3); // gPUasb
```

#### Use padding to make your output ids longer

[](#use-padding-to-make-your-output-ids-longer)

Note that output ids are only padded to fit **at least** a certain length. It doesn't mean that they will be *exactly* that length.

```
use Hashids\Hashids;

$hashids = new Hashids(); // no padding
$hashids->encode(1); // jR

$hashids = new Hashids('', 10); // pad to length 10
$hashids->encode(1); // VolejRejNm
```

#### Using a custom alphabet

[](#using-a-custom-alphabet)

```
use Hashids\Hashids;

$hashids = new Hashids('', 0, 'abcdefghijklmnopqrstuvwxyz'); // all lowercase
$hashids->encode(1, 2, 3); // mdfphx
```

#### Encode hex instead of numbers

[](#encode-hex-instead-of-numbers)

Useful if you want to encode [Mongo](https://www.mongodb.com)'s ObjectIds. Note that *there is no limit* on how large of a hex number you can pass (it does not have to be Mongo's ObjectId).

```
use Hashids\Hashids;

$hashids = new Hashids();

$id = $hashids->encodeHex('507f1f77bcf86cd799439011'); // y42LW46J9luq3Xq9XMly
$hex = $hashids->decodeHex($id); // 507f1f77bcf86cd799439011
```

Pitfalls
--------

[](#pitfalls)

1. When decoding, output is always an array of numbers (even if you encoded only one number):

    ```
    use Hashids\Hashids;

    $hashids = new Hashids();

    $id = $hashids->encode(1);

    $hashids->decode($id); // [1]
    ```
2. Encoding negative numbers is not supported.
3. If you pass bogus input to `encode()`, an empty string will be returned:

    ```
    use Hashids\Hashids;

    $hashids = new Hashids();

    $id = $hashids->encode('123a');

    $id === ''; // true
    ```
4. Do not use this library as a security measure. **Do not** encode sensitive data with it. Hashids is **not** an encryption library.

Randomness
==========

[](#randomness)

The primary purpose of Hashids is to obfuscate numeric ids. It's **not** meant or tested to be used as a security or compression tool. Having said that, this algorithm does try to make these ids random and unpredictable:

There is no pattern shown when encoding multiple identical numbers (3 shown in the following example):

```
use Hashids\Hashids;

$hashids = new Hashids();

$hashids->encode(5, 5, 5); // A6t1tQ
```

The same is true when encoding a series of numbers vs. encoding them separately:

```
use Hashids\Hashids;

$hashids = new Hashids();

$hashids->encode(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // wpfLh9iwsqt0uyCEFjHM

$hashids->encode(1); // jR
$hashids->encode(2); // k5
$hashids->encode(3); // l5
$hashids->encode(4); // mO
$hashids->encode(5); // nR
```

Curse words! #$%@
-----------------

[](#curse-words-)

This code was written with the intent of placing the output ids in visible places, like the URL. Therefore, the algorithm tries to avoid generating most common English curse words by generating ids that never have the following letters next to each other:

```
c, f, h, i, s, t, u

```

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance58

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 70.7% 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 ~8 days

Total

2

Last Release

1066d ago

### Community

Maintainers

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

---

Top Contributors

[![vinkla](https://avatars.githubusercontent.com/u/499192?v=4)](https://github.com/vinkla "vinkla (210 commits)")[![ivanakimov](https://avatars.githubusercontent.com/u/56521216?v=4)](https://github.com/ivanakimov "ivanakimov (27 commits)")[![4kimov](https://avatars.githubusercontent.com/u/56128128?v=4)](https://github.com/4kimov "4kimov (21 commits)")[![arzeth](https://avatars.githubusercontent.com/u/546779?v=4)](https://github.com/arzeth "arzeth (4 commits)")[![albertcht](https://avatars.githubusercontent.com/u/9117929?v=4)](https://github.com/albertcht "albertcht (4 commits)")[![Trismegiste](https://avatars.githubusercontent.com/u/1260026?v=4)](https://github.com/Trismegiste "Trismegiste (4 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (3 commits)")[![ignaciogc](https://avatars.githubusercontent.com/u/44265905?v=4)](https://github.com/ignaciogc "ignaciogc (2 commits)")[![jwpage](https://avatars.githubusercontent.com/u/52687?v=4)](https://github.com/jwpage "jwpage (2 commits)")[![jamband](https://avatars.githubusercontent.com/u/1117087?v=4)](https://github.com/jamband "jamband (2 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (2 commits)")[![ptondereau](https://avatars.githubusercontent.com/u/4287777?v=4)](https://github.com/ptondereau "ptondereau (1 commits)")[![sokool](https://avatars.githubusercontent.com/u/4784286?v=4)](https://github.com/sokool "sokool (1 commits)")[![stof](https://avatars.githubusercontent.com/u/439401?v=4)](https://github.com/stof "stof (1 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (1 commits)")[![tothimre](https://avatars.githubusercontent.com/u/74795412?v=4)](https://github.com/tothimre "tothimre (1 commits)")[![w33ble](https://avatars.githubusercontent.com/u/404731?v=4)](https://github.com/w33ble "w33ble (1 commits)")[![bonfante](https://avatars.githubusercontent.com/u/8030979?v=4)](https://github.com/bonfante "bonfante (1 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")[![leihog](https://avatars.githubusercontent.com/u/385317?v=4)](https://github.com/leihog "leihog (1 commits)")

---

Tags

hashyoutubeencodedecodebitlyidshashidsobfuscatehashid

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/universetech-inc-hashids/health.svg)

```
[![Health](https://phpackages.com/badges/universetech-inc-hashids/health.svg)](https://phpackages.com/packages/universetech-inc-hashids)
```

###  Alternatives

[hashids/hashids

Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers

5.5k48.6M275](/packages/hashids-hashids)[delight-im/ids

Short, obfuscated and efficient IDs for PHP

289.5k1](/packages/delight-im-ids)[sqids/sqids

Generate short YouTube-looking IDs from numbers

5781.4M33](/packages/sqids-sqids)[jenssegers/optimus

Id obfuscation based on Knuth's integer hash method

1.3k4.8M27](/packages/jenssegers-optimus)[torann/hashids

Laravel package for Hashids

54335.1k](/packages/torann-hashids)[elfsundae/laravel-hashid

A simple, elegant way to obfuscate your data by generating reversible, non-sequential, URL-safe identifiers.

415246.3k2](/packages/elfsundae-laravel-hashid)

PHPackages © 2026

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