12345678910111213141516171819202122232425262728 |
- <?php
- include "./config.php";
- include "./ShortUrl.php";
-
- $code = $_GET["c"];
-
- try {
- $pdo = new PDO(DB_PDODRIVER . ":host=" . DB_HOST .
- ";dbname=" . DB_DATABASE,
- DB_USERNAME, DB_PASSWORD);
- }
- catch (PDOException $e) {
- trigger_error("Error: Failed to establish connection to database.");
- exit;
- }
-
- $shortUrl = new ShortUrl($pdo);
- try {
- $url = $shortUrl->shortCodeToUrl($code);
- header("Location: " . $url);
- exit;
- }
- catch (Exception $e) {
- // log exception and then redirect to error page.
- // header("Location: /error");
- header("Location: index.php");
- exit;
- }
|