-
Notifications
You must be signed in to change notification settings - Fork 23
/
redirect.php
48 lines (41 loc) · 1.29 KB
/
redirect.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
<?php
require_once('util4p/util.php');
require_once('util4p/CRObject.class.php');
require_once('Code.class.php');
require_once('Counter.class.php');
require_once('link.logic.php');
require_once('config.inc.php');
require_once('init.inc.php');
if (time() - (int)cr_get_COOKIE('last_visit_time', 0) < 2) { // too fast, seems like an endless loop
$code = Code::TOO_FAST;
require_once('404.php');
exit;
}
setcookie('last_visit_time', time());
$link = new CRObject();
$link->set('token', cr_get_GET('token'));
$res = link_get($link);
if (ENABLE_LOG_QUERY) {
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
$lang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null;
$log = new CRObject();
$log->set('token', cr_get_GET('token', ''));
$log->set('referer', $referer);
$log->set('ua', $ua);
$log->set('lang', $lang);
$log->set('ip', cr_get_client_ip(false));
$log->set('time', time());
Counter::log($log);
}
if ($res['errno'] === Code::SUCCESS) {
header('HTTP/1.1 307 Temporary Redirect');
$url = $res['url'];
if (strpos($url, '//') === false) {
$url = 'http://' . $url;
}
header('Location: ' . $url);
} else {
$code = $res['errno'];
require_once('404.php');
}