Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Whip up a quick stats page, useful if tracking is enabled

  • Loading branch information...
commit af64cc77e6029a08a4712976547d8e3d7cdae8c8 1 parent c5e3a3c
@lozzd authored
Showing with 39 additions and 0 deletions.
  1. +1 −0  rename.htaccess
  2. +38 −0 stats.php
View
1  rename.htaccess
@@ -14,4 +14,5 @@ Options All -Indexes
RewriteEngine On
RewriteRule ^shorten/(.*)$ shorten.php?longurl=$1 [L]
RewriteRule ^([0-9a-zA-Z]{1,10})$ redirect.php?url=$1 [L]
+RewriteRule ^([0-9a-zA-Z+]{1,10})$ stats.php?url=$1 [L]
</IfModule>
View
38 stats.php
@@ -0,0 +1,38 @@
+<?php
+
+require('config.php');
+
+$shorturl = substr($_GET['url'],0,-1);
+$results = mysql_query('SELECT * FROM ' . DB_TABLE . ' WHERE short_url="' . mysql_real_escape_string($shorturl) . '"');
+if ((!$results) || (mysql_num_rows($results) == 0)) {
+ header('HTTP/1.1 404 Not Found');
+ die("404 - This short URL does not exist. ");
+} else {
+ $id = mysql_result($results, 0, 0);
+ $longurl = mysql_result($results, 0, 1);
+ $created = mysql_result($results, 0, 3);
+ $creator = mysql_result($results, 0, 4);
+ $clicks = mysql_result($results, 0, 5);
+}
+?>
+
+<!DOCTYPE html>
+<html>
+<head>
+<title>URL shortener - Stats for <?php echo $shorturl ?></title>
+<meta name="robots" content="noindex, nofollow">
+<style type="text/css">
+#longurl { font-size:20px; padding:10px ; width: 600px}
+body { font-family: "Lucida Grande" }
+li { padding: 4px; }
+</style>
+</head>
+<body>
+<h1>URL Shortener - Stats for <?php echo $shorturl ?></h1>
+<h3><?php echo $clicks ?> clicks</h3>
+<ul>
+<li>Original URL: <a href="<?php echo $longurl ?>"><?php echo $longurl ?></a> </li>
+<li>Created on <?php echo date("r", $created) ?> by <?php echo $creator ?></li>
+</ul>
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.