-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
87 lines (68 loc) · 2.26 KB
/
api.php
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
session_start();
require_once 'includes/db.inc.php';
require_once 'includes/functions.db.inc.php';
?>
<?php
if (!empty($_GET['link'])) {
$url = $_GET['link'];
if (strpos($url, "://") == false) {
$url = "https://" . $url;
}
if (filter_var($url, FILTER_VALIDATE_URL)) {
$shorted = "";
// echo $_GET['custom'];
if (empty($_GET['custom']))
$shorted = uniqueKey($conn, $length = 3);
else {
$key = $_GET['custom'];
$query = "SELECT * FROM urls WHERE shorturl = '$key'";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result)) {
die("0");
$fullURL = $url;
} else {
$shorted = $_GET['custom'];
$fullURL = "";
}
}
$creator = "unknown";
$editcode = randomKey();
$preview = 0;
$captcha = 0;
$passcode = null;
if (!empty($_GET['preview']))
$preview = intval($_GET['preview']);
if (!empty($_GET['captcha']))
$captcha = intval($_GET['captcha']);
if (!empty($_GET['creator']))
$creator = $_GET['creator'];
if (!empty($_GET['passcode']))
$passcode = $_GET['passcode'];
$query = "INSERT INTO urls ( longurl, shorturl, creator, edit, preview, captcha, passcode) VALUES ( '$url', '$shorted', '$creator', '$editcode', '$preview', '$captcha', '$passcode')";
$result = mysqli_query($conn, $query);
if ($result) {
echo $website . $shorted;
$_GET['link'] = "";
} else {
echo '0';
}
} else {
echo '0';
}
} else if ((empty($_GET['link']))&&!empty($_GET['custom'])) {
$key = $_GET['custom'];
$query = "SELECT * FROM urls WHERE shorturl = '$key'";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result)) {
echo '0';
} else {
echo '1';
}
} else {
echo '0';
}
?>
<?php
mysqli_close($conn);
?>