PHPackages                             diarmuidie/niceid - 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. diarmuidie/niceid

ActiveLibrary

diarmuidie/niceid
=================

PHP library to generate short, non-sequential, URL-friendly hashes of incremental IDs. Similar to YouTube (https://www.youtube.com/watch?v=dQw4w9WgXcQ) and Bitly (http://bit.ly/1D0CAzd) URLs.

v1.2.1(7y ago)1557.8k↓50%2MITPHPPHP &gt;=5.6

Since Mar 23Pushed 7y ago2 watchersCompare

[ Source](https://github.com/diarmuidie/NiceID)[ Packagist](https://packagist.org/packages/diarmuidie/niceid)[ Docs](http://github.com/diarmuidie/niceid)[ RSS](/packages/diarmuidie-niceid/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (2)Versions (10)Used By (0)

diarmuidie/niceid
=================

[](#diarmuidieniceid)

PHP library to generate short, non-sequential, URL-friendly hashes of incremental IDs. Similar to YouTube  and Bitly  URLs.

Developed by [Diarmuid](https://diarmuid.ie/).

[![Latest Stable Version](https://camo.githubusercontent.com/cec4ddd8f5d47a68be419b2b9abd7a1fdb3ee2a54d0ae16866692362987310c7/68747470733a2f2f706f7365722e707567782e6f72672f646961726d75696469652f6e69636569642f762f737461626c65)](https://packagist.org/packages/diarmuidie/niceid)[![License](https://camo.githubusercontent.com/9e5bbd2e982f50a326f063bb2c5db1d6ec69c5856f7f3b79ef9ecf39cd647378/68747470733a2f2f706f7365722e707567782e6f72672f646961726d75696469652f6e69636569642f6c6963656e7365)](https://packagist.org/packages/diarmuidie/niceid)[![Build Status](https://camo.githubusercontent.com/f22cd14913f9967d5a818cfef07a83ceae33799a2d85c9dafe1a557d8327e8b6/68747470733a2f2f636c6f75642e64726f6e652e696f2f6170692f6261646765732f646961726d75696469652f4e69636549442f7374617475732e737667)](https://cloud.drone.io/diarmuidie/NiceID)[![SensioLabsInsight](https://camo.githubusercontent.com/4d96b55213a333292e249e66c81bd17688e5907b2e3ea64e76aefba8852267b6/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f33313964666535332d643134652d343738612d393965372d3766373935666133336132622f6d696e692e706e67)](https://insight.sensiolabs.com/projects/319dfe53-d14e-478a-99e7-7f795fa33a2b)

Features
--------

[](#features)

- Non-sequential IDs (i.e. difficult, but not impossible, to guess the next one).
- URL friendly.
- No external dependencies.
- PSR-4 compatible.
- Compatible with PHP &gt;= 5.6

Installation
------------

[](#installation)

You can install NiceID through [Composer](https://getcomposer.org):

```
$ composer require diarmuidie/niceid
```

Usage
-----

[](#usage)

Generate an ID from a int:

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

use Diarmuidie\NiceID\NiceID;

$niceid = new NiceID('Some Random Secret Value');
echo $niceid->encode(123); // uSdqd
```

Notice that a secret is passed to the NiceID constructor. This secret is used to encode and decode the IDs. If the secret changes then IDs cannot be decoded.

Use the decode method to decode the NiceID back to an int.

```
echo $niceid->decode('uSdqd'); // 123
```

You can also change the min length of the NiceID (Defaults to 5 if not specified):

```
$niceid->setMinLength(10);
echo $niceid->encode(123); // uccccccu8p
```

To specify the characters to use in the encoded string use the `setCharacters()` method.

```
$niceid->setCharacters('abcde');
echo $niceid->encode(123); // adcce
```

The default character set is: `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_`

You can even specify a UTF-8 character set if you want:

```
$niceid->setCharacters('ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ');
echo $niceid->encode(123); // ⓖⓑⓥⓘⓘⓠ
```

To Do
-----

[](#to-do)

- Add library to [packagist](http://packagist.org).
- Setup Travis to run unit tests.
- Better handle UTF-8 chars in character string.
- 100% Code coverage for unit tests.
- Refactor `BaseConvert::convert()` method.
- Handle `PHP_INT_MAX` overflow.
- Implement [BCMath](http://php.net/manual/en/book.bc.php) support for integers larger than `PHP_INT_MAX`.
- Setup Drone.io to run unit tests.

Contributing
------------

[](#contributing)

Feel free to contribute features, bug fixes or just helpful advice 😄

1. Fork this repo
2. Create a feature branch
3. Submit a PR ...
4. Profit 😎

Changelog
---------

[](#changelog)

See the [CHANGELOG.md](https://github.com/diarmuidie/niceid/blob/master/CHANGELOG.md) file.

Authors
-------

[](#authors)

- [Diarmuid](http://diarmuid.ie) ([Twitter](http://twitter.com/diarmuidie))

License
-------

[](#license)

The MIT License (MIT)

Copyright (c) 2015 Diarmuid

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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 ~214 days

Recently: every ~361 days

Total

8

Last Release

2574d ago

Major Versions

v0.2.2 → v1.0.02015-08-27

PHP version history (2 changes)v1.1.0PHP &gt;=5.4

v1.2.0PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/8478c1cc380ffdafb9739f9467cd35664307ac413f8baa7fa6f690241c7528f8?d=identicon)[diarmuidie](/maintainers/diarmuidie)

---

Top Contributors

[![diarmuidie](https://avatars.githubusercontent.com/u/707037?v=4)](https://github.com/diarmuidie "diarmuidie (84 commits)")

---

Tags

hashobfuscateidurl-friendly

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/diarmuidie-niceid/health.svg)

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

###  Alternatives

[hashids/hashids

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

5.4k48.6M278](/packages/hashids-hashids)[ramsey/collection

A PHP library for representing and manipulating collections.

1.2k486.0M69](/packages/ramsey-collection)[cybercog/laravel-optimus

An Optimus bridge for Laravel. Id obfuscation based on Knuth's multiplicative hashing method.

192564.1k](/packages/cybercog-laravel-optimus)[cakephp/utility

CakePHP Utility classes such as Inflector, String, Hash, and Security

12127.1M63](/packages/cakephp-utility)[lastguest/murmurhash

MurmurHash3 Hash

12910.2M52](/packages/lastguest-murmurhash)[delight-im/ids

Short, obfuscated and efficient IDs for PHP

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

PHPackages © 2026

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