-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathu.php
More file actions
45 lines (37 loc) · 1.11 KB
/
Copy pathu.php
File metadata and controls
45 lines (37 loc) · 1.11 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
<?php
$code = $_GET['c'] ?? '';
if (!$code) {
http_response_code(400);
exit('No code provided.');
}
$db = json_decode(file_get_contents('db.json'), true);
if (!isset($db[$code]['url'])) {
http_response_code(404);
exit('Short URL not found.');
}
$url = $db[$code]['url'];
// Simple IP-based geolocation
function getGeoInfo($ip) {
$json = @file_get_contents("http://ip-api.com/json/$ip");
return $json ? json_decode($json, true) : null;
}
$ip = $_SERVER['REMOTE_ADDR'];
$geo = getGeoInfo($ip);
// Log info
$log = [
'code' => $code,
'timestamp' => gmdate('c'),
'ip' => $ip,
'userAgent' => $_SERVER['HTTP_USER_AGENT'] ?? '',
'referer' => $_SERVER['HTTP_REFERER'] ?? '',
'language' => $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '',
'city' => $geo['city'] ?? '',
'region' => $geo['regionName'] ?? '',
'country' => $geo['country'] ?? '',
'lat' => $geo['lat'] ?? '',
'lon' => $geo['lon'] ?? ''
];
file_put_contents('logs.jsonl', json_encode($log) . PHP_EOL, FILE_APPEND);
// Redirect instantly
header("Location: $url", true, 302);
exit;