<?php require_once "include/config.php"; require_once "include/ShortUrl.php"; require_once "include/Database.php"; $db = Database::getInstance(); $pdo = $db->getConnection(); $shortUrl = new ShortUrl($pdo); $all_urls = $shortUrl->getAllUrlsFromDb(); $message = ""; if (!empty($_GET)) { $code = array_keys($_GET); if (isset($code[0]) && $code[0] != 'invalid') { $url = $shortUrl->shortCodeToUrl($code[0], true); header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $url); } else { if ($code[0] == 'invalid') { $message = "Please enter a valid url"; } } } ?> <html> <head> <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> <title>URL Shortener</title> <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css" type="text/css"/> </head> <body role='document'> <nav class='navbar navbar-inverse navbar-fixed-top'></nav>
<?php require_once "../includes/config.php"; $shortUrl = new ShortUrl(); try { $url = $shortUrl->shortCodeToUrl($_GET['q']); header("Location: " . $url); } catch (Exception $e) { echo "<h3>Error!</h3>", $e; exit; }
<?php require_once "../include/config.php"; require_once "../include/ShortUrl.php"; if (empty($_GET["c"])) { header("Location: shorten.html"); exit; } $code = $_GET["c"]; try { $pdo = new PDO(DB_PDODRIVER . ":host=" . DB_HOST . ";dbname=" . DB_DATABASE, DB_USERNAME, DB_PASSWORD); } catch (\PDOException $e) { header("Location: error.html"); exit; } $shortUrl = new ShortUrl($pdo); try { $url = $shortUrl->shortCodeToUrl($code); header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $url); } catch (\Exception $e) { print_r($e); header("Location: error.html"); exit; }