diff --git a/index.php b/index.php index 424a152..77f2c03 100644 --- a/index.php +++ b/index.php @@ -15,15 +15,16 @@ switch ($path) { $error = false; $target = null; +$needs_confirmation = false; try { $links = new Links(".links.db", "links.sql"); - $target = $links->getTarget($path); + list($target, $needs_confirmation) = $links->getTarget($path); $links->handleVisit($path); } catch (Exception $exception) { $error = true; } -if ($target != null) { +if ($target != null && !$needs_confirmation) { header("Location: {$target}"); exit(); } @@ -88,20 +89,33 @@ if ($target != null) { Something went wrong internally, and you could not be redirected. Please try again later.



Link not found

The short URL https://fwdkr.co could not be found.



- About fwdkr.co

- You've arrived at this page because you typed or linked to "fwdkr.co", the URL shortcut for - fwdekker.com.

- Whenever you see a "fwdkr.co" link, you can trust that it will always take you to a website affiliated with - FWDekker. + if ($target != null && $needs_confirmation) { + ?> + Confirm redirect

+ This URL redirects to .

+ + Click here to proceed +

+ + About fwdkr.co

+ You've arrived at this page because you typed or linked to "fwdkr.co", the URL shortcut for + fwdekker.com.

+ + Whenever you see a "fwdkr.co" link, you can trust that it will always take you to a website affiliated with + FWDekker. + diff --git a/links.php b/links.php index a224192..2d5e1f2 100644 --- a/links.php +++ b/links.php @@ -43,14 +43,15 @@ class Links * Returns the target to the given path, or null if there is no such target. * * @param string $path the path to return the target of - * @return string|null the target to the given path, or null if there is no such target + * @return array|null the target to the given path and whether confirmation is required before redirecting, or null + * if there is no such target */ - function getTarget(string $path): ?string + function getTarget(string $path): ?array { - $stmt = $this->db->prepare("SELECT * FROM links WHERE path = :path;"); + $stmt = $this->db->prepare("SELECT target, needs_confirmation FROM links WHERE path = :path;"); $stmt->bindValue(":path", $path); if ($result = $stmt->execute()->fetchArray(SQLITE3_ASSOC)) - return $result["target"]; + return array($result["target"], $result["needs_confirmation"]); return null; } diff --git a/links.sql b/links.sql index f2a9cec..557f5fb 100644 --- a/links.sql +++ b/links.sql @@ -1,11 +1,13 @@ +-- auto-generated definition create table links ( - path text not null + path text not null constraint links_pk primary key, - target text not null, - visits int default 0 not null, - last_visit text + target text not null, + needs_confirmation boolean default false not null, + visits int default 0 not null, + last_visit text ); create unique index links_path_uindex