Download the PHP package timch56888/hashids without Composer
On this page you can find all versions of the php package timch56888/hashids. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package 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: https://hashids.org/php
Getting started
Require this package, with Composer, in the root directory of your project.
Then you can import the class into your application:
Note Hashids require either
bcmath
orgmp
extension in order to work.
Quick Example
More Options
A few more ways to pass input ids to the encode()
function:
Making your output ids unique
Pass a project name to make your output ids unique:
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.
Using a custom alphabet
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).
Pitfalls
-
When decoding, output is always an array of numbers (even if you encoded only one number):
- Encoding negative numbers is not supported.
-
If you pass bogus input to
encode()
, an empty string will be returned: - Do 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):
The same is true when encoding a series of numbers vs. encoding them separately:
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:
All versions of hashids with dependencies
ext-mbstring Version *