Shorten URL's with TinyURL or IsGd
Taking a long URL that has been stuffed with keywords for the search engines and making it shorter for use on Twitter or on your Website, Blog or FaceBook page is quite simple. There are many free services available but last week we were asked to create a simple ASP URL "shortener". We chose "TinyUrl" for the service because (1) they require no API or registration (2) the default length of the shortened URL was 25 characters or less (3) the short URL's NEVER expire (4) they feature Direct Redirect and Path Forwarding and (5) they support English, Japanese, Mandarin and Spanish languages. URL shorteners help prevent the longer URLs from breaking layouts because long URLs don't "text wrap" and may force tables to move or <divs> to improperly overflow.
The code is "cut and paste" simple and we've even added a bit of CSS to style the form up a bit. There is an option in the code to use the Is.Gd service instead of TinyUrl by simply "commenting out" one line and "uncommenting" another.
Here is the example with the cut and paste code below (we are using an iframe to display the form on this blog):
<style type="text/css">
<!--
#tinyurlform fieldset {
display : block;
color : #000;
width : 300px;
margin : 0 0 0 0;
padding : 0 15px 15px 15px;
background-color : #fff;
border : 1px solid #999;
}
#tinyurlform fieldset legend {
display : inline;
margin : 0 0 0 0;
padding : 0 0 0 0;
}
#tinyurlform fieldset legend p {
font-weight : bold;
color : #000080;
background-color : #fff;
margin : 0 0 0 0;
padding : 0 10px 0 10px;
}
#tinyurlform fieldset #shortenBtn {
border : 1px inset #369;
color : #000;
background : #9f9;
margin : 10px 0 10px 0;
cursor : pointer;
} -->
</style>
<%
DIM strUrl
strUrl=request.form("strUrl")
%>
<!-- change the form action to the name of your ASP page -->
<form action="tiny_url.asp" method="post" name="form1" id="form1">
<fieldset>
<legend><p>Tiny URL</p></legend>
<label for="strUrl">Paste your long URL here</label>
<input name="strUrl" type="text" id="strUrl" value="<%=strUrl%>" size="40" />
<br />
<input name="shortenBtn" type="submit" id="shortenBtn" value="Shorten URL" />
<br />
<%
If strURL<>""then
DIM oXml,strShortUrl,strReturnVal
strShortUrl = "http://tinyurl.com/api-create.php?url=" & strUrl
'To use is.gd instead of TinyUrl simply comment out the above line with an apostrophe
'and uncomment the line below by removing the apostrophe
'strShortUrl = "http://is.gd/api.php?longurl=" & strUrl
set oXml = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
oXml.Open "GET", strShortUrl, false
oXml.Send
strReturnVal = oXml.responseText
Set oXml = nothing
shortenUrl = strReturnVal
Response.Write("<a rel=""nofollow"" href=""" & shortenUrl & """>" & shortenUrl & "</a>" )
end if
%>
</fieldset>
</form>

Comments
1. Although I am quite content with the shortening plugin I use at my sight, I am intrigued by the code above that makes it possible for us to bitly-shorten our long URLs right on our sites with the use of the above described form.by moralde
PJ
by Affordable Website Designs
by Sue Tedford