Use of Xrl.in
To make it easier for developers to use there is an API for creating links on Xrl.In. To create a link simply fetch http://xrl.in/?r=key&xrl=http://your.link/here which will return the id for that link. The id can then be attached to either http://xrl.in/ or http://preview.xrl.in/. The results may sometimes return ! which is an indication that the entered link was invalid. Below you can find a few examples of how to use this in several programing languages.
All these examples require the use of some programing language, if you after a simple method of including this in your site see HTML code.
PHP
<?php
$link = 'http://your.link/here'; // maybe $_REQUEST['xrl']
if (function_exists('curl_init')) {
$ch = curl_init('http://xrl.in/?r=key&xrl=' . urlencode$link));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, 'deflate,gzip');
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$xrl_id = curl_exec($ch);
} else {
$xrl_id = file_get_contents('http://xrl.in/?r=key&xrl=' . urlencode($link));
}
if($xrl_id == '!'){
die('URL was invalid');
}
echo('http://xrl.in/'.$xrl_id);
?>
JavaScript
function fetchXrlInLink(link)
{
var httpRequest;
if (window.XMLHttpRequest)
{ // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
if (httpRequest.overrideMimeType)
{
httpRequest.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject)
{ // IE
try
{
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e)
{
try
{
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return;
}
httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
httpRequest.open('GET', 'http://xrl.in/?r=key&xrl=' + encodeURIComponent(link), true);
httpRequest.send('');
}
function alertContents(httpRequest)
{
if (httpRequest.readyState == 4)
{
if (httpRequest.status == 200)
{
var response = httpRequest.responseText;
if(response != '!')
{
alert('http://xrl.in/' + response);
} else
{
alert('The URL was invalid');
}
} else
{
alert('There was a problem with the request.');
}
}
}
fetchXrlInLink('http://your.link/here');
Other Languages
If you know how to use Xrl.in in another programing language with out an example here please email it to the owner of codefisher.org (& xrl.in) to have it included here.