Download the PHP package zhujinkui/hashlib without Composer
On this page you can find all versions of the php package zhujinkui/hashlib. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zhujinkui/hashlib
More information about zhujinkui/hashlib
Files in zhujinkui/hashlib
Package hashlib
Short Description Hashlib is 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: http://hashids.org/php
License Apache-2.0
Informations about the package hashlib
hashlib
Hashlib是一个小型PHP库,可以从数字中生成类似YouTube的ID,当您不想将数据库ID暴露给用户时使用它。
hashlib is 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: http://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:
Quick Example
More Options
A few more ways to pass to encode()
:
Make your ids unique:
Pass a project name to make your ids unique:
Use padding to make your ids longer:
Note that ids are only padded to fit at least a certain length. It doesn't mean that your ids will be exactly that length.
Pass 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 encode 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 tool and do not encode sensitive data. This is not an encryption library.
Randomness
The primary purpose of Hashids is to obfuscate 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:
No repeating patterns showing there are 3 identical numbers in the id:
Same with incremented numbers:
Curses! #$%@
This code was written with the intent of placing created 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:
License
MIT License. See the LICENSE file. You can use Hashids in open source projects and commercial products. Don't break the Internet. Kthxbye.