Mercurial > hg > egg-tcls
changeset 307:30bb894cfb58
Updated a bit.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 27 Jan 2015 13:13:44 +0200 |
parents | 9858b93387a2 |
children | 45ada1ddc63b |
files | urlredirect.php.txt |
diffstat | 1 files changed, 14 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/urlredirect.php.txt Tue Jan 27 08:44:15 2015 +0200 +++ b/urlredirect.php.txt Tue Jan 27 13:13:44 2015 +0200 @@ -1,7 +1,7 @@ <? /* ========================================================== * URLLog PHP-script for redirecting ShortURLs - * (C) Copyright 2006-2011 Tecnic Software productions (TNSP) + * (C) Copyright 2006-2015 Tecnic Software productions (TNSP) * ========================================================== * How to set up short URL redirection: * @@ -26,8 +26,18 @@ * * 6) Profit. */ -// SQLite3 database file path and name -$dbFilename = "/path/to/urllog.sqlite"; +try { + // You need to uncomment and configure one of the PDO object + // initialization lines below, depending on what kind of SQL + // database you are using. + + // If using SQLite3, set the filename / path there: + //$db = new PDO("sqlite:/path/to/urllog.sqlite"); +} +catch (PDOException $e) { + myerr("Could not connect to URL database: ".$e->getMessage()."."); +} + // ========================================================== // Helper functions @@ -71,14 +81,7 @@ myerr("Invalid ID."); -// Find the URL -try { - $db = new PDO("sqlite:".$dbFilename); -} -catch (PDOException $e) { - myerr("Could not connect to URL database: ".$e->getMessage()."."); -} - +// Find the matching URL, if any foreach ($db->query("SELECT url FROM urls WHERE id=".$urlID) as $row) { header("Location: ".$row["url"]);