-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_url.php
36 lines (26 loc) · 865 Bytes
/
make_url.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
<?php
if (isset($_POST['url'])) {
$url = $_POST['url'];
if (filter_var($url, FILTER_VALIDATE_URL)) {
include 'base62.php';
include 'sql.php';
$db = new SafeMySQL();
$url_hash = hash('haval128,3', $url);
$sql = 'SELECT `id` FROM `urls` WHERE `hash` = ?s LIMIT 1';
$item = $db->getRow($sql, $url_hash);
if (!empty($item)) {
$enc_id = Base62::encode($item['id']);
echo 'http://localhost/redirect/' . $enc_id;
} else {
$sql = 'INSERT INTO `urls` SET ?u';
$db->query($sql, array('url' => $url, 'hash' => $url_hash));
$id = $db->insertId();
$enc_id = Base62::encode($id);
echo 'http://localhost/redirect/' . $enc_id;
}
} else {
echo 'Не вірна URL-адреса';
}
} else {
echo 'Не передано потрібних параметрів';
}