-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.php
More file actions
41 lines (30 loc) · 991 Bytes
/
proxy.php
File metadata and controls
41 lines (30 loc) · 991 Bytes
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
<?php
$url = $_SERVER['QUERY_STRING'] ?? '';
if (strpos($url, 'url=') === 0) { $url = substr($url, 4); $url = urldecode($url); }
if (empty($url)) {
http_response_code(400);
echo "Error: No URL provided";
exit;
}
if (!preg_match('#^https?://#i', $url)) { $url = 'https://' . $url; }
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
if (isset($_SERVER['HTTP_USER_AGENT'])) { curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); }
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
if (curl_errno($ch)) {
http_response_code(502);
echo "" . curl_error($ch);
curl_close($ch);
exit;
}
curl_close($ch);
if ($content_type) {
header("Content-Type: $content_type");
}
http_response_code($http_code);
echo $response;