s2u.php 608 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. include "./config.php";
  3. include "./ShortUrl.php";
  4. $code = $_GET["c"];
  5. try {
  6. $pdo = new PDO(DB_PDODRIVER . ":host=" . DB_HOST .
  7. ";dbname=" . DB_DATABASE,
  8. DB_USERNAME, DB_PASSWORD);
  9. }
  10. catch (PDOException $e) {
  11. trigger_error("Error: Failed to establish connection to database.");
  12. exit;
  13. }
  14. $shortUrl = new ShortUrl($pdo);
  15. try {
  16. $url = $shortUrl->shortCodeToUrl($code);
  17. header("Location: " . $url);
  18. exit;
  19. }
  20. catch (Exception $e) {
  21. // log exception and then redirect to error page.
  22. // header("Location: /error");
  23. header("Location: index.php");
  24. exit;
  25. }