Mercurial > hg > egg-tcls
comparison urlredirect.php.txt @ 307:30bb894cfb58
Updated a bit.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 27 Jan 2015 13:13:44 +0200 |
parents | 68c4b25c982c |
children | 6c999a7ac6d9 |
comparison
equal
deleted
inserted
replaced
306:9858b93387a2 | 307:30bb894cfb58 |
---|---|
1 <? | 1 <? |
2 /* ========================================================== | 2 /* ========================================================== |
3 * URLLog PHP-script for redirecting ShortURLs | 3 * URLLog PHP-script for redirecting ShortURLs |
4 * (C) Copyright 2006-2011 Tecnic Software productions (TNSP) | 4 * (C) Copyright 2006-2015 Tecnic Software productions (TNSP) |
5 * ========================================================== | 5 * ========================================================== |
6 * How to set up short URL redirection: | 6 * How to set up short URL redirection: |
7 * | 7 * |
8 * 1) Set up URLLog database (see urllog.tcl for more information) | 8 * 1) Set up URLLog database (see urllog.tcl for more information) |
9 * | 9 * |
24 * | 24 * |
25 * 5) You may need to restart/reload your www-server. | 25 * 5) You may need to restart/reload your www-server. |
26 * | 26 * |
27 * 6) Profit. | 27 * 6) Profit. |
28 */ | 28 */ |
29 // SQLite3 database file path and name | 29 try { |
30 $dbFilename = "/path/to/urllog.sqlite"; | 30 // You need to uncomment and configure one of the PDO object |
31 // initialization lines below, depending on what kind of SQL | |
32 // database you are using. | |
33 | |
34 // If using SQLite3, set the filename / path there: | |
35 //$db = new PDO("sqlite:/path/to/urllog.sqlite"); | |
36 } | |
37 catch (PDOException $e) { | |
38 myerr("Could not connect to URL database: ".$e->getMessage()."."); | |
39 } | |
40 | |
31 | 41 |
32 // ========================================================== | 42 // ========================================================== |
33 // Helper functions | 43 // Helper functions |
34 function urlToID($url) | 44 function urlToID($url) |
35 { | 45 { |
69 $urlID = urlToID($urlStr); | 79 $urlID = urlToID($urlStr); |
70 if ($urlID < 0) | 80 if ($urlID < 0) |
71 myerr("Invalid ID."); | 81 myerr("Invalid ID."); |
72 | 82 |
73 | 83 |
74 // Find the URL | 84 // Find the matching URL, if any |
75 try { | |
76 $db = new PDO("sqlite:".$dbFilename); | |
77 } | |
78 catch (PDOException $e) { | |
79 myerr("Could not connect to URL database: ".$e->getMessage()."."); | |
80 } | |
81 | |
82 foreach ($db->query("SELECT url FROM urls WHERE id=".$urlID) as $row) | 85 foreach ($db->query("SELECT url FROM urls WHERE id=".$urlID) as $row) |
83 { | 86 { |
84 header("Location: ".$row["url"]); | 87 header("Location: ".$row["url"]); |
85 exit; | 88 exit; |
86 } | 89 } |