PHP Classes

Bijection URL shortening: Encode and decode values for short URLs

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 400 This week: 1All time: 6,566 This week: 571Up
Version License PHP version Categories
bijection 1.1Artistic License5.0PHP 5, Libraries, Code Generation
Description 

Author

This class can encode and decode values for short URLs.

It can take a given id number for a short URL that will eventually be stored in a database and generates a sequence of random characters that will be used to associate to the short URL of the given id.

The generated short URL may have an optional check digit.

The class can also that a previously generated short URL and decode it to find the original identifier number or the URL.

Innovation Award
PHP Programming Innovation award nominee
September 2015
Number 9
URL shortening services are very popular. Usually they store in a database a long URL that corresponds to a short character sequence.

This class implements an algorithm that makes the short URL character sequence be derived by a number that can be the id of the database record stored in a database.

This fact allows saving an additional field that would otherwise be used to store the short URL key.

The use of a check digit allows doing prior validation of short URLs without performing a database lookup.

These details make this algorithm more efficient than the traditional ways used to map short to long URLs.

Manuel Lemos
Picture of Zhao
  Performance   Level  
Name: Zhao <contact>
Classes: 3 packages by
Country: Japan Japan
Age: 47
All time rank: 22909 in Japan Japan
Week rank: 420 Up2 in Japan Japan Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php

use rbib\util\string\encode\Bijection;

include
'rbib/util/string/encode/Bijection.php';

$bijection = (new Bijection());
//create short url based on int(100)
$encode_id = $bijection->encode(100);
echo
$encode_id; //aNbC

//decode the short url to int (100)
$decode_id = $bijection->decode($encode_id);
echo
$decode_id; //100



  Files folder image Files  
File Role Description
Files folder imagerbib (1 directory)
Accessible without login Plain text file example.php Example demo for short url

  Files folder image Files  /  rbib  
File Role Description
Files folder imageutil (1 directory)

  Files folder image Files  /  rbib  /  util  
File Role Description
Files folder imagestring (1 directory)

  Files folder image Files  /  rbib  /  util  /  string  
File Role Description
Files folder imageencode (1 file)

  Files folder image Files  /  rbib  /  util  /  string  /  encode  
File Role Description
  Plain text file Bijection.php Class URL shortening algorithm

 Version Control Unique User Downloads Download Rankings  
 0%
Total:400
This week:1
All time:6,566
This week:571Up