-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredirect.php
More file actions
51 lines (44 loc) · 1.32 KB
/
redirect.php
File metadata and controls
51 lines (44 loc) · 1.32 KB
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
<?php
include($_SERVER['DOCUMENT_ROOT'] . "/includes/inc-db-connection.php");
include($_SERVER['DOCUMENT_ROOT'] . "/includes/inc-functions.php");
function isBot($user_agent) {
$bot_list = array(
'Googlebot',
'Bingbot',
'Slurp',
'DuckDuckBot',
'Baiduspider',
'YandexBot',
'Sogou',
'Exabot',
'Facebot',
'PetalBot',
'AhrefsBot',
'SemrushBot'
);
foreach ($bot_list as $bot) {
if (stripos($user_agent, $bot) !== false) {
return true;
}
}
return false;
}
?>
<?php
if (empty($_GET['redirect'])) {
stderr("URL <strong>not</strong> provided.");
} else {
$shortUrl = $_GET['redirect'];
$redirect = DB::getInstance()->selectValues("SELECT * FROM `shorteners` WHERE `shortener_short`='{$shortUrl}'");
if (count($redirect) > 0) {
$update = isset($_GET['redirect']) ? updateRedirectClicks($redirect['shortener_id']) : '';
if (!isBot($_SERVER['HTTP_USER_AGENT'])) {
$clicks = recordClicks($_SERVER['REQUEST_URI'], getRealIp());
}
header("Location: {$redirect['shortener_original_url']}");
exit;
} else {
stderr("Invalid redirect <strong>URL</strong>.");
}
}
?>