-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
27 lines (22 loc) · 694 Bytes
/
api.php
File metadata and controls
27 lines (22 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
// Configurations
include_once('include/config/config.php');
// Database Singleton
include_once("include/config/Database.php");
// URL Shortener Class
include_once("include/shortener/Shortener.php");
try {
if (!empty($_REQUEST['url'])) {
$url = urldecode($_REQUEST['url']);
// Instantiate Shortener
$shortener = new Shortener();
// Get domain
$domain = $_SERVER['HTTP_HOST'] . "/";
// Create new short code or get old if it already exists
$short = $shortener->insertNewURL($url);
$shortCodeURL = $domain . $short;
echo $shortCodeURL;
}
} catch (Exception $e) {
echo "Error! " . $e->getMessage();
}