Today’s fun task

While awaiting the arrival of another box, add a restful API to the micro url shortener.

The very brief url shortener is a php script which, in seven lines of overly-simple php code, implements a reasonably fast url shortener.

<?php
 
$links = parse_ini_file( 'urls.ini' );
 
if( isset( $_GET['l'] ) && array_key_exists( $_GET['l'], $links ) ){
    header( 'Location: ' . $links[$_GET['l']] );
}else{
    header( 'HTTP/1.0 404 Not Found' );
    echo 'Unknown link.';
}

This opens a text .ini file and reads it in one slurp into an array. It then checks if a short code was passed, and if not (or if the code passed was not found) it reports an unknown link. Otherwise, it returns a header which forwards the browser to the url.

This works quite well, in practice. Url forwarding is quick, pretty much seamless. But, short codes must be manually added to a text file on the server.

The plan is to add a crude restful api (side note: Lorna Jane blog) which can allow token identification, and create/edit/delete of short codes. Why tokens? because it is simpler, and should be faster to create.