23 lines
423 B
PHP
23 lines
423 B
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
$short_code = $_GET['code'] ?? null;
|
|
|
|
if (!$short_code) {
|
|
header("Location: /");
|
|
exit;
|
|
}
|
|
|
|
$pdoconnection = db();
|
|
$stmt = $pdoconnection->prepare("SELECT original_url FROM links WHERE short_code = ?");
|
|
$stmt->execute([$short_code]);
|
|
$link = $stmt->fetch();
|
|
|
|
if ($link) {
|
|
header("Location: " . $link['original_url']);
|
|
exit;
|
|
} else {
|
|
header("Location: /");
|
|
exit;
|
|
}
|