Created
February 4, 2016 10:41
-
-
Save igran/088ca188fd57a689d3de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
ob_start(); | |
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | |
// Open the cURL session | |
$curlSession = curl_init(); | |
curl_setopt($curlSession, CURLOPT_URL, $url); | |
curl_setopt($curlSession, CURLOPT_HEADER, 1); | |
curl_setopt($curlSession, CURLOPT_PROXY, '10.100.0.1:4444'); | |
#curl_setopt($curlSession, CURLOPT_HTTPHEADER, | |
# array('Host: ' . $_SERVER['HTTP_HOST'])); | |
if($_SERVER['REQUEST_METHOD'] == 'POST'){ | |
$postinfo = ''; | |
foreach($_POST as $key=>$value) { | |
$postinfo .= $key.'='.urlencode($value).'&'; | |
} | |
rtrim($postinfo,'&'); | |
curl_setopt ($curlSession, CURLOPT_POST, 1); | |
curl_setopt ($curlSession, CURLOPT_POSTFIELDS, $postinfo); | |
} | |
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER,1); | |
curl_setopt($curlSession, CURLOPT_TIMEOUT,300); | |
//Send the request and store the result in an array | |
$response = curl_exec ($curlSession); | |
// Check that a connection was made | |
if (curl_error($curlSession)){ | |
// If it wasn't... | |
print curl_error($curlSession); | |
} else { | |
$ar = explode("\r\n\r\n", $response, 2); | |
$header = $ar[0]; | |
$body = $ar[1]; | |
//handle headers - simply re-outputing them | |
$header_ar = explode("\r\n",$header); | |
foreach($header_ar as $header){ | |
$header = trim($header); | |
if(!preg_match("/^Transfer-Encoding/",$header)){ | |
header($header); | |
} | |
} | |
print $body; | |
} | |
curl_close ($curlSession); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment