forked from Rehike/Rehike
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simplefunnel.php
51 lines (43 loc) · 1.25 KB
/
simplefunnel.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
<?php
$host = 'https://www.youtube.com/'; // leading / is IMPORTANT!
$hostvalue = 'www.youtube.com';
// Resolve the request method:
switch($_SERVER['REQUEST_METHOD']) {
case 'GET': $reqmethod = 'GET'; break;
case 'POST': $reqmethod = 'POST'; break;
}
// Retrieve POST fields (if post):
if ($reqmethod == 'POST') {
$postfields = file_get_contents('php://input');
} else {
$postfields = '';
}
// Passthrough all request headers_list:
$httpheader = array();
$httpheader[] = 'Host: '.$hostvalue;
foreach (getallheaders() as $name => $value) {
if (!in_array($name, ['Accept','Accept-Encoding','Host'], true)) {
$httpheader[] = $name.': '.$value;
}
}
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$ua = $_SERVER['HTTP_USER_AGENT'];
} else {
$ua = '';
}
$curlarray = array(
CURLOPT_CUSTOMREQUEST=>$reqmethod,
CURLOPT_POSTFIELDS=>$postfields,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_HEADER=>0,
CURLOPT_FOLLOWLOCATION=>1,
CURLOPT_HTTPHEADER=>$httpheader,
CURLOPT_USERAGENT=>$ua);
// echo json_encode($curlarray); //debug
$ch = curl_init($host.$_SERVER['REQUEST_URI']);
curl_setopt_array($ch, $curlarray,);
$response_body = curl_exec($ch);
$contenttype = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
header('Content-Type: '.$contenttype);
echo $response_body;
curl_close($ch);