www.htmlgoodies.com/beyond/php/article.php/3859411
|
By Lee Underwood January 19, 2010 URL shortening services such as tinyurl.com, bit.ly, and poprl are very popular and have a wide array of uses across the Web. For instance, shortened URLs can be used in e-mail and forum postings. It's also advisable to use shortened URLs in newsletters as many spam filters sometimes interpret several, long URLs as spam. And shortened URLs are, of course, a requirement when using Twitter. In addition to saving space, shortened URLs also make for easier reading. In addition to the basic URL shortening services, many organizations have gotten into the act, e.g., Facebook, Google, even the Republican party. However, you might want to consider where some of these services originate. As Wired.com recently noted, some of these services are in countries that support terrorism, e.g., Bit.ly. "ly" is the country code for Libya, a country with ties to terrorism. You can find a list of country codes on the IANA Web site. Roll Your Own
Instead of concerning yourself with all of those details, you could just create your own URL shortening service. You can offer it for use by the general public or for your own personal use. In addition, this is a great method for getting the URL of your Web site spread around the Web. Although the actual link would usually go to a different site, your main domain would still be there, e.g., There are many different scripts to choose from. One of them is an easy-to-use script created by Harry (yep, just "Harry."). It's call "Harryjerry Linx" and is very simple to implement. Harry is currently working on additional features to enhance the usefulness of the script. All you need is a Web hosting account with PHP/MySQL support. Installing the ScriptFirst, you will need to download the script and uncompress the file.
Next, upload all the files to your server. It's best to use one letter for the directory name where the files reside to keep it short as it will be included in the shortened URL, e.g.,
Next, create a MySQL database on your Web server. If you've never done this before, and have a Web host that is using cPanel, it's really pretty simple. (There is also a great MySQL video tutorial available for all the steps below.)
To create the database, go to the database area in cPanel and select the "MySQL Database Wizard." Enter a name for the database, e.g.,
Once you have created the database, open the
define('MYSQL_USER', 'harryjrc_linx');
define('MYSQL_PASS', 'pb650917');
define('MYSQL_DB', 'harryjrc_linx');
On the first line (
Finally, you'll need to import the contents of the Testing the Script
Now, if you point your browser to <p><a href="http://yoursite.com/l/">Another one</a></p>
It's nothing magical; it'll just reload the page. But it's easier to click on the link than to go to the reload button in the browser (do not remove the ConclusionThat's it! There is nothing left to do but to start shrinking those URLs! If you're offering the page to the general public, you can change the page to anything you like. Just be aware that there is not a lot of security with this script, as far as stopping others from using it. But if you don't tell others, they won't really know it's there. However, you shouldn't really have any problems with it. If you have any questions, you can ask Harry. You can also leave a comment if you like the script. |