-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
50 lines (38 loc) · 1.39 KB
/
Copy pathindex.php
File metadata and controls
50 lines (38 loc) · 1.39 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
46
47
48
49
50
<?php
/**
* ======================================================================================
* PHP PROXY SERVER
* ======================================================================================
* Please Keep This Credit
* --------------------------------------------------------------------------------------
* Repository : https://github.com/sunuazizrahayu/php-proxy-server
*
* ======================================================================================
*/
$application_server = '1.2.3.4';
$uri = $_SERVER['REQUEST_URI'];
$curl = curl_init("http://{$application_server}{$uri}");
// CATCH ALL HEADERS REQUEST
$catchHeaders = getallheaders();
$headers = array();
if(!empty($catchHeaders)) {
foreach ($catchHeaders as $header => $value) {
$headers[] = "$header: $value";
}
}
// HANDLE REQUEST
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl,CURLOPT_POSTFIELDS,$_POST);
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$data = curl_exec($curl);
// do something with $data, transform it however you want...
//OUTPUT SETTINGS
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); //SET STATUS CODE
http_response_code($httpcode);
$contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE); //SET CONTENT-TYPE
header('Content-Type: '.$contentType);
//output
echo $data;