We need a link to be shortened.

", false, "400 Client Failed", "

Missing URL

"); } if ( ! preg_match("/^[a-z]+:\/\/[a-z0-9_]+/i", $_POST["url"]) ){ failure("

Only schemas like http:// or ftp:// are supported.

", false, "400 Client Failed", "

This does not look like an url

"); } require 'db.php'; $hash = md5($_POST["url"]); if( ! $short = $db->get($hash)){ $arr = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); $short=""; for ($i=0;$i<5;$i++){ $r = mt_rand(0, count($arr)-1); $short.=$arr[$r]; } $db->set($short, $_POST["url"]); $db->set($hash, $short);; } failure("

Your short link for ".htmlentities($_POST["url"])." is
http://".$_SERVER["HTTP_HOST"]."/-".$short."

", false, "200 OK", "

Success

");