Download the PHP package alexanderzon/hashids without Composer

On this page you can find all versions of the php package alexanderzon/hashids. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hashids

hashids

======

Full Documentation

A small PHP class to generate YouTube-like ids from numbers. Read documentation at http://hashids.org/php

hashids

Installation

You can install Hashids thru Composer (packagist has hashids/hashids package). In your composer.json file use:

And run: php composer.phar install. After that you can require the autoloader and use Hashids:

Updating from v0.3 to 1.0?

Read the CHANGELOG at the bottom of this readme!

Example Usage

The simplest way to use Hashids:

string(5) "laHquq"
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}

And an example with all the custom parameters provided (unique salt value, minimum id length, custom alphabet):

string(5) "514cdi42"
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}

Curses! #$%@

This code was written with the intent of placing created ids in visible places - like the URL. Which makes it unfortunate if generated hashes accidentally formed a bad word.

Therefore, the algorithm tries to avoid generating most common English curse words. This is done by never placing the following letters next to each other:

c, C, s, S, f, F, h, H, u, U, i, I, t, T

Big Numbers

Each number passed to the constructor cannot be negative or greater than 1 billion by default (1,000,000,000). Hashids encode() function will return an empty string if at least one of the numbers is out of bounds. Be sure to check for that -- no exception is thrown.

PHP starts approximating numbers when it does arithmetic on large integers (by converting them to floats). Which is usually not a big issue, but a problem when precise integers are needed.

However, if you have either GNU Multiple Precision --with-gmp, or BCMath Arbitrary Precision Mathematics --enable-bcmath libraries installed, Hashids will increase its upper limit to PHP_INT_MAX which is int(2147483647) on 32-bit systems and int(9223372036854775807) on 64-bit.

It will then use regular arithmetic on numbers less than 1 billion (because it's faster), and one of these libraries if greater than. GMP takes precedence over BCMath.

You can get the upper limit by doing: $hashids->get_max_int_value(); (which will stay at 1 billion if neither of the libraries is installed).

Speed

Even though speed is an important factor of every hashing algorithm, primary goal here was encoding several numbers at once while avoiding collisions.

On a 2.26 GHz Intel Core 2 Duo with 8GB of RAM, it takes about:

  1. 0.000093 seconds to encode one number.
  2. 0.000240 seconds to decode one id (while ensuring that it's valid).
  3. 0.493436 seconds to generate 10,000 ids in a for loop.

On a 2.7 GHz Intel Core i7 with 16GB of RAM, it takes roughly:

  1. 0.000067 seconds to encode one number.
  2. 0.000113 seconds to decode one id (and ensuring that it's valid).
  3. 0.297426 seconds to generate 10,000 ids in a for loop.

Sidenote: The numbers tested with were relatively small -- if you increase them, the speed will obviously decrease.

Notes

Changelog

2.0.0:

1.0.5:

1.0.3 & 1.0.4:

1.0.2

1.0.1

1.0.0

0.3.1

0.3.0 - Warning: Hashes change in this version:

0.2.1

0.2.0 - Warning: Hashes change in this version:

0.1.3 - Warning: Hashes change in this version:

0.1.2 - Warning: Hashes change in this version:

0.1.1

0.1.0

Contact

I am on the internets @IvanAkimov

License

MIT License. See the LICENSE file. You can use Hashids in open source projects and commercial products. Don't break the Internet. Kthxbye.


All versions of hashids with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package alexanderzon/hashids contains the following files

Loading the files please wait ....