Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPMaster.com:
Building Your Own URL Shortener
Sep 21, 2012 @ 17:58:00

On PHPMaster.com today, there's a new tutorial walking you through the creation of a URL shortner - a simple tool that can be used to compact URLs into something easier to manage (and more friendly with services like Twitter).

Most of us are familiar with seeing URLs like bit.ly or t.co on our Twitter or Facebook feeds. These are examples of shortened URLs, which are a short alias or pointer to a longer page link. [...] In this article you’ll learn how to create a fully functional URL shortener for your website that will work whether you use a front controller/framework or not. If you use a front controller, I’ll discuss you how to easily integrate this URL shortener without having to dig into the controller’s programming.

They help you create a simple database to hold the link relationships, the PHP code to create the randomized hash that represents the link and the code to shorten it. There's also the PHP code to take it the other way and decode the shortened version into the full URL. You can find the full code (ready for checkout) over on the PHPMaster.com Github account.

tagged: url shortener service tutorial database

Link:

Derick Rethans' Blog:
Short URLs
Feb 22, 2011 @ 15:44:13

Derick Rethans has shared a method he's created for making short, descriptive URLs with the help of his translit PHP extension that translates non-latin characters into latin ones.

The URLs for my articles are automatically generated from the title. There is a little function that uses translit's transliterate() function to ASCII-ify the titles. [...] However, [this] is hardly a short URL. What we want is something short and descriptive. First of all, I thought it would work to generate short URLs automatically.

In hindsight, though, he decided it would just be better to come up with his own short URLs but he still wanted a way to use them. Registering a short domain helped and, along with some <link> tags, made it easier for the right information to be automatically found.

tagged: short url shortener translit tutorial

Link:

phpRiot.com:
Shortening URLs for goo.gl with Google's URL Shortener API
Jan 12, 2011 @ 16:06:41

On phpRiot.com there's a new tutorial showing you how to use the Google URL shortener API in your PHP applications (via a curl call).

In 2010 Google released its own URL shortener, which allows you to shorten URLs to use the goo.gl domain. In this article I will show you how to easily create your own short URLs using their new URL shortener API. Note: This API is still in labs, meaning the API is subject to change without notice.

The tutorial steps you through the process of getting an API key for your scripts to use for access and what the message needs to be for the POST request to the Google service. His example script defines the API key and endpoint as well as a basic "shortenUrl" method that takes in the long URL to shorten. The curl request posts the data as JSON and receives a json-encoded message back with the original URL and the ID you wanted it shortened to.

tagged: google shortener api tutorial curl

Link:

Jonathan Snook's Blog:
Building a URL Shortener (with CakePHP)
Apr 27, 2009 @ 17:06:23

With recent discussions about URL shortners, Jonathan Snook decided to work up his own quick version using some of the built-in routing of the CakePHP framework.

With all the talk of URL shortening services, I decided to add a quick service into Snook.ca, which is run on CakePHP, to redirect a short URL to a post. Because my static content already has short URLs and all I have are posts, creating a short URL handler for it was very easy.

His shortener is used on his posts for his blog to redirect the smaller URLs back to the post they reference. The result is a route that connects something like "/s/id_number" over to the correct post (as seen here). He also offers a suggestion for a "super-compressed" URL tat converts it down to a three-character shortened version that can then be easily converted back down to the decimal equivalent.

tagged: cakephp framework url shortener short route custom

Link:


Trending Topics: