vinkla/hashids
vinkla/hashids has 5,425 GitHub stars and 411 forks. GitHot measured +1 stars in 24 hours and +1 in 7 days. Last checked 2026-11-11 18:19 UTC. Last push 2026-04-16.
A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.
측정된 스타 증가
- in 24h
- +1
- in 7 days
- +1
- in 15 days
- 업데이트 지연
- in 1 month
- 업데이트 지연
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalHashids 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: https://hashids.org/php
[!NOTE] The creator of Hashids has released a new, upgraded version rebranded as Sqids. However, Hashids will continue to be maintained and available for future use. For more information, please visit the Sqids repository and learn how it compares to Hashids on the Sqids website.
Getting started
Require this package, with Composer, 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
bcmathorgmpextension in order to work.
Quick Example
use Hashids\Hashids;
$hashids = new Hashids();
$id = $hashids->encode(1, 2, 3); // o2fXhV
$numbers = $hashids->decode($id); // [1, 2, 3]
More Options
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
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
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
use Hashids\Hashids;
$hashids = new Hashids('', 0, 'abcdefghijklmnopqrstuvwxyz'); // all lowercase
$hashids->encode(1, 2, 3); // mdfphx
Encode hex instead of numbers
Useful if you want to encode Mongo'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
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]Encoding negative numbers is not supported.
If you pass bogus input to
encode(), an empty string will be returned:use Hashids\Hashids; $hashids = new Hashids(); $id = $hashids->encode('123a'); $id === ''; // trueDo not use this library as a security measure. Do not encode sensitive data with it. Hashids is not an encryption library.
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! #$%@
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
관련 프로젝트 살펴보기
Asabeneh/30-Days-Of-Python
30 Days of Python 프로그래밍 챌린지는 Python 프로그래밍 언어를 30일 동안 배우기 위한 단계별 가이드입니다. 이 챌린지는 100일 이상 걸릴 수 있습니다. 자신의 속도에 맞춰 진행하세요. 다음 동영상도 도움이 될 수 있습니다: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,618 스타grafana/grafana
개방적이고 조합 가능한 옵저버빌리티 및 데이터 시각화 플랫폼입니다. Prometheus, Loki, Elasticsearch, InfluxDB, Postgres 등 여러 소스의 메트릭, 로그, 트레이스를 시각화합니다.
77,859 스타redis/redis
실시간 데이터 기반 애플리케이션을 구축하는 개발자에게 Redis는 가장 선호되고, 가장 빠르며, 기능이 가장 풍부한 캐시, 데이터 구조 서버이자 문서 및 벡터 쿼리 엔진입니다.
77,472 스타apache/superset
Apache Superset는 데이터 시각화 및 데이터 탐색 플랫폼입니다.
75,495 스타