PHPDeveloper.orghttp://www.phpdeveloper.org
Up-to-the Minute PHP News, views and communityen-usTue, 03 Mar 2015 12:59:31 -060030http://www.phpdeveloper.org/news/18506http://www.phpdeveloper.org/news/18506
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.

]]>Fri, 21 Sep 2012 12:58:00 -0500http://www.phpdeveloper.org/news/15940http://www.phpdeveloper.org/news/15940
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.

]]>Tue, 22 Feb 2011 09:44:13 -0600http://www.phpdeveloper.org/news/15726http://www.phpdeveloper.org/news/15726
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.

]]>Wed, 12 Jan 2011 10:06:41 -0600http://www.phpdeveloper.org/news/12412http://www.phpdeveloper.org/news/12412
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.