From 1d4606db27c47264a4eed701c4b5df1b4450c271 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Thu, 8 Jun 2023 21:36:33 -0500 Subject: [PATCH] Added code to redirect the user if the database query returns a URL --- redirect.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/redirect.php b/redirect.php index ee9eaae..999bdaa 100644 --- a/redirect.php +++ b/redirect.php @@ -1,5 +1,36 @@ withPersistentSessions(true)->build(); + $keyspace = 'glink'; + $session = $cluster->connect($keyspace); + + $statement = $session->prepare('SELECT url FROM data WHERE shortlink=? ALLOW FILTERING;'); + $result = $session->execute($statement,array('arguments' => array($uri))); + + if ($result->count() == 0) { + printf('The given GLink was invalid, and doesn\'t point to a specific web page.'); + exit; + } + + foreach($result as $row) { + if (is_null($row)) { + printf('The given GLink was invalid, and doesn\'t point to a specific web page.'); + exit; + } else { + header("Location: " . $row['url']); + } + } + } ?>