1. Start
  2. Installation
  3. Admin Panel
    1. Basic Settings
    2. Instant redirect or ads
  4. Cron Jobs
  5. API Documentation
  6. PHP Code
    1. Shortener Algorithm
    2. How to short
    3. How to decode
  7. Update
    1. Version 0.2
    2. Version 0.1

URL Shortner


Thank you for purchasing this item. If you have have some problems, please contact me: roman.codecanyon@gmail.com


Before install make sure that the following files and folders are executable (has 0777 permissions)

  1. Upload files to your web server or hosting.
  2. Run installation file (http://domain.name/install.php)
  3. This file will check one more time your server reuirements and after all you will need to fill setting fields.
  4. After that press "install" button to install your app.
  5. After installation you will see you site and admin panel URLs
  6. WARNING! After installation REMOVE install.php file and change admin login and password in admin panel.

Note. If your main index.php file located not in the root folder - you need to add RewriteBase /subfolder/ into .htaccess file after RewriteEngine on

Admin Panel

Basic Settings


Admin Panel's URL is domain.name/admin
By default login is admin and password is admin. Don't forget to change them.
Settings > Admin
In this are you can change administrator's login, password, name.
Settings > Language
Here you can add your own phrase translation.
Settings > Share
Here you can customize you social network settings. For example edit og meta propirties, add application image and customize social like buttons (Facebook, Twitter, GPlus)
Settings > Basic
In this are you can edit your SEO (Keyword, Title, Description), application name, add verification codes (Google, Bing, Yandex). In addition, you can turn on/off QR-Code,  add banner,  or JS scripts (for example: Google Analytics).
Settings > Basic > API_Request
The limit of requests for each user per day. Set 0 to remove limitations.

Instant redirect or ads


If you want to make more money from advertising, you can set countdown timer in admin panel (Settings > Basic > Redirect Timer) and add any ads code in /web/root/app/views/frontend/application/redirect.php
For example if you decide to make 5 second countdown timer then user will wait 5 seconds before redirect and look at ads ;)

Cron Jobs


This is optional feature. Just if you have set limitation for requests, then it would be good to clean expired data after each day. To do this, you should setup cron command.
All you need is to add following line into your cron job shedule.
0 2 * * * /usr/bin/php /path/to/web/root/app/yiic.php clearstat >/dev/null 2>&1
0 2 * * * Time and date for your task. In our case cron will be executed each day at 2:00 a.m
/usr/bin/php path to php command
/path/to/web/root/app/yiic.php physical path to script
clearstat Command name
>/dev/null 2>&1 this mean that all output from this command should be shoved into a black hole. I.e just do nothing with output.


API Documentation


Developers can easy use this API by request http://domain.name/api?url=your_long_url URL.
This service can handle 3 response methods:
Array (serialized)
You will get response as serialized array

PHP Code


Note. This app based on Yii framework.
All backend and frontend controllers are located in /web/root/dir/app/controllers/{backend/frontend}/
All backend and frontend views are located in /web/root/dir/app/views/{backend/frontend}/
Config file located in  /web/root/dir/app/config/main.php
DB Config file located in /web/root/dir/app/config/db.php

Shortener Algorithm

This algorithm based on Bijective Function  which allows you to use maximum of possible records to store. For example maximum value of unsigned BIGINT field is 18 446 744 073 709 551 615 the short id will be only v8QrKbgkrAq

How to short


File:  /web/root/dir/app/controllers/frontend/ApplicationController.php
Function: ActionShort
// Get the last insert id
$id = Shortlink::model()->insertLink($url);
//Get short link ID by integer
$shortLink = Yii::app()->shortlink->shortByID($id);
//And insert short ID into DB
Shortlink::model()->updateLinkByID($id, $shortLink)) ;

How to decode


File:  /web/root/dir/app/controllers/frontend/ApplicationController.php
Function: ActionRedirect
//Get integer from shortID
$id = Yii::app()->shortlink->getID($shortid);
//Get url by integer
$url = Shortlink::model()->findByPk($id);




Version 0.2

- Added countdown timer before redirect. Be default countdown timer is equal 0, it mean that user will redirect instant. If you want to make more money from ads, you can set timer to 5 seconds and add any ads code in /web/root/app/views/frontend/application/redirect.php

For people who have bought the earlier version:

 Firstly, run this 3 queries in db


UPDATE `sl_basic_settings` SET Redirect = 0;
INSERT INTO sl_lang_settings (`Key`, `Value`, `end`) VALUES ('Redirect_Timer', 'You will be redirected to %s in %s second(-s)', 'front');
Overwrite this folders (or all project if you want)
app/models/, app/controllers/, app/views
Remove cache files (/web/root/app/runtime/cache)

Version 0.1

- Bug fix (prevent to shorten the same URL multiple times)