include_once 'config.php'; $template = new UrlTemplate(); if (array_key_exists("redirect", $_GET)) { try { $db = new UrlShortner($database); header("Location: " . $db->get($_GET['redirect'])); } catch (Exception $e) { echo $template->error($e->getMessage()); } } else { if (array_key_exists("preview", $_GET)) { try { $db = new UrlShortner($database); echo $template->preview($db->get($_GET['preview'])); } catch (Exception $e) { echo $template->error($e->getMessage()); } } else { if (array_key_exists("url", $_GET)) { try { $db = new UrlShortner($database); echo $template->link($db->insert($_GET['url'])); } catch (Exception $e) { echo $template->error($e->getMessage()); } } else { echo $template->index(); } } } ##testing my git setup
<?php error_reporting(0); header("Content-Type: text/plain"); include_once 'config.php'; include_once 'UrlShortner.class.php'; if (!function_exists('json_encode')) { include_once 'json.php'; } if (!isset($_GET['url']) or empty($_GET['url'])) { die(json_encode(array("Error" => "No link Detected"))); } try { $db = new UrlShortner($database); echo json_encode(array("short_link" => $db->insert($_GET['url']))); } catch (Exception $e) { die(json_encode(array("Error" => $e->getMessage()))); }