Twitter? PHP? Yes!

I’ve heard from a lot of people that twitter shortens URLs, apparently if they’re more than 30 characters. This means that something like would take the full 30, even without an image. I’ve taken a look into what you can do to shorten the URLs you use for your own images:

  1. Top-level domains: If you use instead of, you can slash four characters
  2. Root image folder: If you place a folder for your twitter images in your root, you can point to that folder, such as or
  3. Invisible PHP: If you have a index.php in your folder, you can go to and the server will find the index for you. Send it parameters, such as i for image name, and either g, p, or j for .gif, .png, or .jpg, respectively:

In that final example, the URL is exactly thirty characters long.

For those who want to the PHP script, I have it below:

list($key, $value) = each($_GET);
if(isset($key) && $key != 'p' && $key != 's' && $key != 'm' && $key != 'cat')
{ //wordpress uses 'p', 's', 'm', and 'cat' for posts

$pretension = "<img src='img/twitter/";
$extension = ".bmp' />";
$extension = ".gif' />";
$extension = ".png' />";
$extension = ".jpg' />";

header("Location: http://www.".$key.".com/");
echo $pretension . $key . $extension;

}else{/*do regular index stuff */}

In this snippet, I paste it before the stuff of my wordpress index. certain GET keys are taken by WordPress, so those can never be my first key. As long as it isn’t, it’ll accept it as a short url, and you can use ‘p’ or ‘cat’ or such as the second or later key. Go to to try it out. I’ve set it up so that ‘s’ means the sites I’ve made (I’ve made two, so 1 and 2), followed by a design revision (I only have one recorded on s1, but I have four revisions on s2). So try changing that from s2a to s2b, s2c, or s2d. The ‘p’ at the end denotes a .png file. If you put ‘h’, it’ll take it as an HTML page and redirect you.

If you’re the intensive type, you could set up an array on that page which will match the $key to a list of longer filenames in an associative array, which would let you not rename everything. If you’re referring to other sites, you’ll have to do this.

The way I see it, the shortest you could go is to put
in which you have a maximum of 62 links ($key, from the above PHP example, would be a-z, 0-9, or A-Z), all of a pre-determined type. You could get a four-letter domain-name and something like .ca to shorten it further. Overkill? Yes; but I’m just saying, thirteen characters are possible.

So here’s the challenge: make yourselves or your clients a page where you upload an image, that image is placed in a ‘twitter’ folder in the images directory, the filename is added to the array, the user is given a link to paste, and the there’s some $_GET code in the index.php file that takes a visitor to the content described by the link. I’ll have to throw my own implementation up, though it would be completely useless for twitter while I have such a name as icosidodecahedron (seventeen characters).
I’ll try importing html files, too.

Tags: , ,

Leave a Reply