-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathproxy.php
103 lines (88 loc) · 2.55 KB
/
proxy.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
$query = null;
switch ($_SERVER['REQUEST_METHOD']) {
case 'GET':
$query = $_GET['q'];
get($query);
break;
case 'POST':
$query = $_POST['url'];
post($query, $_POST);
break;
default:
die('Invalid request method');
}
function get($query)
{
if ($query == "") :
header('Content-Type: application/json');
echo json_encode([
"status" => "error",
"message" => "No query specified"
]);
return;
endif;
$url = base64_decode($query);
$ch = curl_init();
$user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1';
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$getHeader = curl_getinfo($ch);
if ($getHeader["redirect_url"] != "") :
$url = $getHeader["redirect_url"];
curl_setopt($ch, CURLOPT_URL, $url);
$output = curl_exec($ch);
endif;
if ($output === '') :
$error = curl_error($ch);
http_response_code(500);
echo json_encode([
"status" => "error",
"message" => $error
]);
return;
endif;
curl_close($ch);
header("Content-Type: " . $getHeader['content_type']);
echo $output;
}
function post($query, $data)
{
if ($query == "") :
header('Content-Type: application/json');
echo json_encode([
"status" => "error",
"message" => "No query specified"
]);
return;
endif;
$url = base64_decode($query);
$ch = curl_init();
$user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1';
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
$getHeader = curl_getinfo($ch);
if ($getHeader["redirect_url"] != "") :
$url = $getHeader["redirect_url"];
curl_setopt($ch, CURLOPT_URL, $url);
$output = curl_exec($ch);
endif;
if ($output === '') :
$error = curl_error($ch);
http_response_code(500);
echo json_encode([
"status" => "error",
"message" => $error
]);
return;
endif;
curl_close($ch);
header("Content-Type: " . $getHeader['content_type']);
echo $output;
}