-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrip-proxy.php
More file actions
44 lines (35 loc) · 1 KB
/
Copy pathrip-proxy.php
File metadata and controls
44 lines (35 loc) · 1 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
<?php
declare(strict_types=1);
$url = $_GET['url'] ?? '';
if ($url === '' || !filter_var($url, FILTER_VALIDATE_URL)) {
http_response_code(400);
header('Content-Type: text/plain; charset=utf-8');
echo 'Invalid URL';
exit;
}
$parts = parse_url($url);
$scheme = strtolower($parts['scheme'] ?? '');
if (!in_array($scheme, ['http', 'https'], true)) {
http_response_code(400);
header('Content-Type: text/plain; charset=utf-8');
echo 'Only http and https URLs are allowed';
exit;
}
$context = stream_context_create([
'http' => [
'timeout' => 15,
'follow_location' => 1,
'max_redirects' => 5,
'user_agent' => 'RIPscrip Viewer Proxy',
],
]);
$data = @file_get_contents($url, false, $context);
if ($data === false) {
http_response_code(502);
header('Content-Type: text/plain; charset=utf-8');
echo 'Could not fetch remote URL';
exit;
}
header('Content-Type: text/plain; charset=utf-8');
header('Access-Control-Allow-Origin: *');
echo $data;