You are here
Home > Php > Short Link Generator in PHP

Short Link Generator in PHP

short-link-generator

Hello friends, today we are going to see a code for short link generator in php. I am sharing this code specially on the suggestion of one of my friend. You may have already know bitly and tinyurl most popular for url shortening service. The same concept is behind this code also. If you want to provide same service like bitly and tinyurl then just book a domain and host this code. Before start coding we need to create database and table. You can create database with any name of your choice then select it and execute below sql query and its done.

Now the coding part

config.php

Here replace root with your database username, test with your database name and paste your password in empty string as in my case i have not setup password that’s why it is empty string.

shorten.php

code to make url short

index.php

code to process short url

.htaccess

Rewrite rules to bring all the request to index.php to process short url and to access shorten.php to short url with and without .php extension. Here RewriteBase /url-shortener can be replace with / if you are hosting it on main domain instead of sub-folder in my case.

Screenshots

url-shortener-1 url-shortener-2
url-shortener-3 url-shortener-4
url-shortener-5 url-shortener-6
url-shortener-7 url-shortener-8

NetBeans Project Download

 

Thanks friends
Please don’t forget to share

Rajesh Kumar Sahanee
I am a passionate Java Developer and I like Computer Programming. I love to do some interesting experiments and listening music in my free time.
https://www.zatackcoder.com

Comments

zatackcoder
Top