changeset 15:c19e9ad24d86

Backed out.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 05 Sep 2011 16:19:29 +0300
parents 929768c2aa86
children 916cffa4f3a1
files urllog.php.txt
diffstat 1 files changed, 57 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/urllog.php.txt	Mon Sep 05 16:19:29 2011 +0300
@@ -0,0 +1,57 @@
+<?
+// =====================================================
+// URLLog PHP-script for redirecting ShortURLs
+// (C) Copyright 2006 Tecnic Software productions (TNSP)
+// =====================================================
+
+// URLLog datafile
+$urlFilename = "data.urllog";
+
+// =====================================================
+// Helper functions
+$idStr = "ABCDEFGHIJKLNMOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+
+function myerr() {
+	header("Status: 404 Not Found");
+	echo "404 Not Found";
+	exit;
+}
+
+// Check arguments
+if (!isset($argv[0])) myerr();
+
+// Calculate urlID
+$urlStr = $argv[0];
+$urlLen = strlen($urlStr);
+if ($urlLen < 1) myerr();
+
+for ($urlID = 0, $i = 0; $i < $urlLen; $i++) {
+	$urlID *= strlen($idStr);
+
+	$n = strpos($idStr, $urlStr[$i]);
+	if ($n !== FALSE) {
+		$urlID += $n;
+	} else
+		myerr();
+}
+
+// Find the URL
+$urlFile = fopen($urlFilename, "r");
+if (!$urlFile) myerr();
+
+$urlFound = 0;
+while (!feof($urlFile) && !$urlFound) {
+	$urlItems = split(" ", fgets($urlFile, 4096), 5);
+	if ($urlItems[4] == $urlID) $urlFound = 1;
+}
+
+fclose($urlFile);
+
+// Output result
+if ($urlFound) {
+	header("Location: ".$urlItems[0]);
+} else
+	myerr();
+
+exit;
+?>
\ No newline at end of file