fcOnTheWeb Logo Web technologies, made easy.

fcOnTheWeb Red DotHow to make a long URL shorter

TinyURL is a great, service offering shorter URLs that are much more portable.

The concept is simple: the user enters a long URL - the sort you might get from a shopping cart or similar, that has a variety of variables set at the end - and TinyURL then gives you a 25 character URL in its place. This is obviously much more user friendly. You simply enter this new, shorter URL into the browser, and you are directed to the original URL. Easy.

So, at fcOnTheWeb, we have created our own version.

It's quite simple really. The submitted long URL is written to the database with an accompanying, random hash value. The new, shorter URL is then returned to the user for them to take in place of the original URL.

Here's the algorithm we use to create the random hash:

$hash_is_verified = false;

while ($hash_is_verified == false) {

$random_hash = get_random_hash();

if (check_random_hash_in_db($random_hash)) {

 

} else {

$hash_is_verified = true;

}

}

...

function get_random_hash() {

$random_hash = "";

$letters_array = array("a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");

for ($i = 0; $i < 7; $i = $i + 1) {

$random_hash = $random_hash . $letters_array[array_rand($letters_array)];

}

return $random_hash;

}

The URL is run through the first section of code, which generates a random string for it. Each time a random string is returned, it's checked to see if it is present in the database (check_random_hash_in_db()). If it is, we generate another random string. This continues over and over until we generate a unique string. That string (hash) is then entered into the database, along with the original URL and the other necessary details.

When generating the random string, there are a couple of things to be considered. We thought about using a sequential system, such as aaaaaaa, aaaaaaab, aaaaaaac, etc. but that would then make it very easy for people to enter random hashes and access URLs that had been submitted by other people. That was the main factor in deciding to use a random system. We used a mixture of upper case and lower case letters and numbers to give a large number of possible hashes. However, some characters are missing - we removed 'similar' characters (such as O and 0, I and l) so as to make the humanly readable hashes more user friendly. The current combination has 21,083,232,519,264,920,575 possible combinations.

When the new, shorter URL is accessed (entered into the browser), the database finds the original URL related to the hash, and the user is then directed to that page. If the submitted URL doesn't begin with an http, then one is appended to it.

function validate_url($provided_url) {

if (strpos($provided_url, "http") > -1) {

return $provided_url;

} else {

return "http://" . $provided_url;

}

}

...

header("Location: " . validate_url($long_url));

Simple really. You can try it for yourself, by entering a URL below. You will then be provided with a short URL, which you can preview, or copy. When entered back into your browser, you will be directed to the original URL.

Unfortunately, the length of fcOnTheWeb.com (14 characters) tends to make URLs a bit longer than the convenient TinyURL.com (11 characters), and the "http://" further adds to it, but you understand the point of the exercise.

While this service works well here, there is a more accessible version available for you to use, at http://fcOnTheWeb.com/url.php. This service will remain in place indefinitely, so you can use it as you wish.

Enjoy, and happy URL shortening.

Long URL:

ferrari_chris

oakley sunglasses cheap (http://www.oakleysunglassescheap.us.com/) says:

2014-07-12 02:06:20

http://www.oakleysunglassescheap.us.com/ oakley sunglasses

cheap
http://www.coachoutletstoreonlineco.com/ coach factory outlet
http://www.abercrombie-andfitch.com/ abercrombie and fitch
http://www.michaelkors-outletsonline.com/ michael kors outlet
http://www.oakley-sunglassesoutlet.com/ oakley sunglasses

outlet
http://www.tory-burchoutlet.com/ tory burch outlet
http://www.abercrombieandfitchstore.com/ abercrombie & fitch
http://www.rayban--sunglasses.com/ ray ban sunglasses
http://www.fit-flops.co.uk/ fitflops
http://www.coachoutlet-factoryonline.com/ coach factory outlet
http://www.toryburch-shoes.com/ tory burch shoes
http://www.coachstoreonline.org/ coach outlet store online
http://www.coachfactory-outletinc.com/ coach factory outlet
http://www.cheapraybansunglasses.us/ cheap ray ban sunglasses
http://www.valentino.us.com/ valentino
http://www.fitfloponline.co.uk/ fitflop uk
http://www.coach-outletinc.com/ coach outlet
http://www.coachoutlet-factorystore.com/ coach outlet store

online
http://www.airjordan.us.com/ air jordan
http://www.timberlandshoesus.com/ timberland shoes
http://www.michaelkorsoutlet-online.us/ michael kors outlet
http://www.coachfactoryoutletnew.com/ coach factory outlet
http://www.coach-factoryoutletinc.com/ coach factory outlet
http://www.truereligionbrandjeans.us.com/ true religion outlet
http://www.truereligionjeans.us.com/ true religion jeans
http://www.coach--handbags.com/ coach outlet online
http://www.louisvuitton--outlet.us/ louis vuitton outlet
http://www.timberland--shoes.com/ timberland boots
http://www.isabelmarantshoes.us.com/ isabel marant shoes
http://www.coachoutletonline-factory.com/ coach outlet online
http://www.michaelkorsoutlet-online.net/ michael kors purses
http://www.louisvuitton-handbag.us/ louis vuitton handbags
http://www.coach-outletstoreonline.com/ coach outlet store

online
http://www.true-religion-jeans.com/ true religion jeans
http://www.coach-outletfactoryonline.com/ coach factory outlet

online
http://www.officialcoachfactoryoutlet.com/ coach factory outlet
http://www.louisvuitton-outlet.org/ louis vuitton outlet
http://www.coach-factoryoutlets.com/ coach factory outlet
http://www.coach-outletonline.us/ coach outlet online
http://www.michaelkorsoutletonlinestore.us/ michael kors outlet
http://www.michaelkorsoutletstoresco.com/ michael kors outlet

store
http://www.tiffanysjewelry-co.com/ tiffany and co jewelry
http://www.celineoutlet-online.com/ celine outlet
http://www.cheap-toms.net/ toms shoes
http://www.celine-handbags.com/ celine handbags
http://www.toms--shoes.us/ toms outlet
http://www.fitflopsandalssale.com/ fitflops
http://www.fitflopusaonline.com/ fitflop outlet
http://www.prada-handbag.com/ prada handbags
http://www.tiffanyandcoinc.com/ tiffany jewelry
http://www.prada-outlet.org/ prada outlet
http://www.michael-korsoutletinc.com/ michael kors
http://www.marcjacobs.us.com/ marc jacobs
http://www.supra.us.com/ supra shoes
http://www.ralphlauren.us.com/ polo ralph lauren
http://www.tiffanyjewelry.us.com/ tiffany jewelry
http://www.shoestoms.net/ toms shoes

__________

POLO says:

2014-08-04 02:56:22

http://www.superbagsmarket.com/ Super Bags Market
http://www.nike-jordanshoes.com/ Nike Jordan Shoes
http://www.thebeatsbydre.net/ Beats By Dre Outlet
http://www.michaelusakors.com/ Michael Kors Outlet Online
http://www.polo-tshirts.com/ Ralph Polo Outlet Online
http://www.northsclearance.com/ North Clearace Outlet
http://www.polo-ralphlaurenonline.com/ Ralph Polo Outlet
http://www.guccishoesuk-2014.net/ Gucci Shoes Outlet
http://www.michaelkorsstates.com/ Michael Kors Outlet
http://www.polooutlet-store.com/ Polo Outlet Store
http://www.ralph-laurenhome.com/ Ralph Lauren UK
http://www.marcjacobsonsale.com/ Marc Jacobs On Sale
http://www.mcmworldwides.com/ MCM Outlet
http://www.salongchamppairs.com/ Sac Longchamp Pairs
http://www.canada-gooser.com/ Canada Goose Outlet
http://www.burberrybags2014.com/ Burberry Outlet
http://www.michaelkors.so/ Michael Kors Outlet
http://www.oakley-sunglassfactory.com/ Oakley Sunglaases Factory
http://www.north-faceoutlet.us.com/ North Face Outlet Online
http://www.moncler-clearance.com/ Moncler Clearance
http://www.woolrich-clearance.com/ Woolrich Clearance
http://www.barbour-jacketsoutlet.com/ Barbour Jackets Outlet Online
http://www.moncler-jacketsoutletonline.com/ Moncler Jackets Outlet Online
http://www.monsterbeatsbydres.net/ Monster Beats Outlet
http://www.louis-vuittonblackfriday.com/ Louis Vuitton Outlet
http://www.lv-guccishoesfactory.com/ Louis Vuitton Factory
http://www.mcmoutlet-jp.com/ MCM 店铺
http://www.cheapdiscountoutlet.com/ Discount Clothes Sale
http://www.michael-korsfactoryonline.com/ Michael Kors Factory Online
http://www.coach-factoryoutlets.net/ Coach Factory Outlet
http://www.coach-blackfriday.net/ Coach Black Friday
http://www.coach-storeoutletonline.com/ Coach Store Outlet Online
http://www.coach-factoryoutletonlines.com/ Coach Factory Outlet Online
http://www.coachcoachoutlet.net/ Coach Outlet
http://www.coach-factory.net/ Coach Factory
http://www.coach-pursesoutlet.net/ Coach Purses Outlet Online
http://www.coach-outletonline.net/ Coach Outlet USA
http://www.mksfactoryoutlet.com/ Michael Kors Factory Outlet
http://www.zxcoachoutlet.com/ Coach Outlet Online USA
http://www.mischristmas.com/ Coach Factory Outlet Online
http://www.misblackfriday.com/ Black Friday
http://www.newoutletonlinemall.com/ Coach Purses Outlet Online
http://www.clickmichaelkors.com/ Michael Kors USA
http://www.cmichaelkorsoutlet.com/ Michael Kors Outlet USA
http://www.ralphlaurenepolo.com/ Ralph Lauren Polo

__________

victoria secret uk (http://www.horsehackers.com) says:

2014-11-13 20:15:44

So have at it, and enjoy!

__________

http://www.identita.fr (http://www.identita.fr) says:

2014-11-13 20:35:27

So have at it, and enjoy!

__________

Мустафа (http://zdeslove.ru) says:

2015-03-10 14:00:24

http://tokmok.org
http://forum.tokmok.org
http://photo.tokmok.org
http://board.tokmok.org
http://love.tokmok.org
http://pogoda.tokmok.org
http://test.tokmok.org
http://rusfolder.tokmok.org
http://forex.tokmok.org
http://my.tokmok.org
http://files.skriptavod.ru
http://shop.tokmok.org
http://mail.tokmok.org
http://demo.skriptavod.ru
http://zdeslove.ru
http://skriptavod.ru
http://newsprogon.ru
http://inmarket-money.ru
http://zataboi.ru
http://love.dsoo.ru

__________

Migukapy (http://sildenafdosage.com) says:

2017-10-30 17:51:21

Drugs Onn Line Viagra Radio Commercial <a href=http://cheapvia25mg.com>buy viagra online</a> Cephalexin 500 Mgs Dosage For Pneumonia Buy Kamagra In Canada Propecia Effects On Women Interactions

__________

Migukapy (http://sildenafdosage.com) says:

2017-10-30 17:51:22

Drugs Onn Line Viagra Radio Commercial <a href=http://cheapvia25mg.com>buy viagra online</a> Cephalexin 500 Mgs Dosage For Pneumonia Buy Kamagra In Canada Propecia Effects On Women Interactions

__________

Migukapy (http://sildenafdosage.com) says:

2017-10-30 17:51:26

Drugs Onn Line Viagra Radio Commercial <a href=http://cheapvia25mg.com>buy viagra online</a> Cephalexin 500 Mgs Dosage For Pneumonia Buy Kamagra In Canada Propecia Effects On Women Interactions

__________

Migukapy (http://sildenafdosage.com) says:

2017-10-30 17:51:32

Drugs Onn Line Viagra Radio Commercial <a href=http://cheapvia25mg.com>buy viagra online</a> Cephalexin 500 Mgs Dosage For Pneumonia Buy Kamagra In Canada Propecia Effects On Women Interactions

__________

ylq says:

2017-11-27 23:12:17

http://chiefs.nfl-jerseys.org/, http://www.adidas-store.net/, http://www.raybans.org.es/, http://www.the-northface.ca/, http://ravens.nfl-jerseys.org/, http://raiders.nfl-jerseys.org/, http://www.nike-free5.com/, http://www.outlet-pradahandbags.com/, http://www.versace-outletonline.com/, http://www.burberryoutlet-inz.co.uk/, http://www.jackets-thenorthface.com/, http://www.northfacejackets.fr/, http://www.vans-shoesoutlet.co.uk/, http://spurs.nba-jersey.com/, http://www.cheap-baseballbats.us/, http://lions.nfl-jerseys.org/, http://www.christian-louboutin.jp.net/, http://www.michaelkorsoutlet.mex.com/, http://www.ferragamo.net.co/, http://www.christianlouboutins-shoes.co.uk/, http://www.outlet-pradabags.com/, http://www.coach-outlet.net.in/, http://www.mcm-bagsoutlet.com/, http://www.air-huarache-shoes.co.uk/, http://www.tommy-hilfigers.de/, http://www.soccershoes.us.com/, http://www.new-balanceshoes.com/, http://www.cheapshoes.net.co/, http://www.airmax.com.se/, http://www.nikeshoes-outlet.com/, http://www.nba-jersey.com/, http://broncos.nfl-jerseys.org/, http://www.coachfactory.cc/, http://www.hollister.com.se/, http://heat.nba-jersey.com/, http://www.hollister-store.com.co.co/, http://www.rayban-sunglasses.fr/, http://www.oakleys-outlets.net/, http://www.nikeair-max.ca/, http://hawks.nba-jersey.com/, http://hornets.nba-jersey.com/, http://www.armani-outlet.com/, http://www.kate-spadebags.com/, http://www.oakleys-sunglass.com.co/, http://www.philipp-pleins.com/, http://www.cheap-jordans.com.co/, http://www.michaels-korsoutlet.com/, http://www.replica-handbags.com.co/, http://www.oakley-sunglassessale.com.co/, http://www.nike-airmax.com.de/, http://www.oakley-sbocco.it/, http://www.asicsoutlet.net/, http://www.australia-oakleysunglasses.com/, http://www.nba-shoes.com/, http://www.dsquared2s.com/, http://www.adidas-shoes.ca/, http://falcons.nfl-jerseys.org/, http://titans.nfl-jerseys.org/, http://steelers.nfl-jerseys.org/, http://www.longchamp-outlet.com.co/, http://www.ralph-lauren-polos.us.org/, http://www.ralphlauren-polos.com.co/, http://www.nike-shoesoutlet.com/, http://www.michaelkors.so/, http://www.thomassabos-jewelrys.co.uk/, http://www.iphone-cases.net/, http://www.newbalance-canada.ca/, http://panthers.nfl-jerseys.org/, http://chargers.nfl-jerseys.org/, http://www.reebok-shoes.co.uk/, http://www.oakleys.org.es/, http://mavericks.nba-jersey.com/, http://www.juicy-coutureoutlet.com/, http://www.oakleysoutlet.com.co/, http://www.michael-korsukpurse.co.uk/, http://www.nike-rosherun.co.nl/, http://warriors.nba-jersey.com/, http://www.omegas-relojes.es/, http://www.outlet-toryburch.com/, http://www.jerseys-store.com/, http://www.polos-ralphlauren.com.co/, http://www.vansschuhe.com.de/, http://www.bottega-venetasoutlet.com/, http://www.outlets-polo.com/, http://www.zcoachoutlet.com/, http://www.nikeshoes.de/, http://www.mcm-backpacks.com.co/, http://www.nike-maxshoes.fr/, http://www.hogans.com.de/, http://www.ed-hardy.us.com/, http://www.cheap-iphonecases.com/, http://www.levis-jeansoutlet.com/, http://www.ferragamos.us.com/, http://www.louboutinshoes.jp.net/, http://www.barboursjackets.com/, http://www.nike-airmaxsc.co.uk/, http://www.asicsoutlet.com.co/, http://browns.nfl-jerseys.org/, http://www.airjordans-shoes.com/, http://www.the-northface.com.de/, http://www.cheap-jerseys.mex.com/, http://buccaneers.nfl-jerseys.org/, http://www.barbours.us.com/, http://www.rolexwatch-outlet.com/, http://www.outlet-mkors.com/, http://www.nike-shoesoutlet.us.org/, http://www.montblancpences.com/, http://www.michael-korsoutletonline.com.co/, http://www.coachoutletonlinemall.com/, http://www.coachoutlet-online.com.co/, http://www.polosoutlet-store.com/, http://www.eyeglassesinsale.com/, http://www.nike-paschers.fr/, http://www.valentino-shoesoutlet.us.com/, http://pelicans.nba-jersey.com/, http://www.marc-jacobs.us.com/, http://www.michaelkors.co.nl/, http://www.timberlandspaschere.fr/, http://www.danskoshoes.in.net/, http://www.burberry

__________

Shirleys Davis (https://www.softtrix.com/organic-seo-services/) says:

2018-01-05 04:38:44

Nice information! Sometimes we need to short the url due to several reasons like character limit, not acceptance or other. Keep posting the informative article.


Add your comment on this article below:

Sorry, there's an error with your form entries. We really appreciate your comment, so please try again.

Form submitting now...

Name:

Website:

Email address (not displayed):

Enter your comment below: