示例#1
0
<?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>