""
);
/* ------------------------------------------------------- */
/* Internal code */
/* ------------------------------------------------------- */
// check fopen is allowed
if (ini_get('allow_url_fopen') != '1') {
die('no fopen support');
}
// load content
$content = "";
$proxiedUrl = $_REQUEST["proxiedUrl"];
if( $proxiedUrl == "" ) {
$surveyUrl = str_replace("https", "http", $surveyUrl);
$content = file_get_contents($surveyUrl);
if ($content === false) {
die("Failed to load content of $surveyUrl");
}
} else {
$proxiedUrl = str_replace("https", "http", $proxiedUrl);
$response = httpRequest($proxiedUrl, $_SERVER['QUERY_STRING'], "POST");
$content = $response["content"];
}
// change form target and method to our proxy
preg_match('/action=\\"(\S*)\\"/', $content, $matches);
$googleUrl = $matches[1];
$content = str_replace($googleUrl, "survey.php", $content);
// add the real action URL as a hidden field
$proxiedUrlTag = '';
$content = str_replace("", $proxiedUrlTag, $content);
// change form method to GET
$content = str_replace('method="POST"', 'method="GET"', $content);
// actual replacements
foreach ($replacements as $k => $v) {
$content = str_replace($k, $v, $content);
}
// print
echo $content;
function httpRequest($url, $data, $method = "GET", $referer='') {
$url = parse_url($url);
$host = $url['host'];
$path = $url['path'];
$query = $url['query'];
$method = strtoupper($method);
$fp = fsockopen($host, 80, $errno, $errstr, 60);
if ($fp){
fputs($fp, "$method http://$host$path?$query HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
if ($referer != '') fputs($fp, "Referer: $referer\r\n");
if ($method == 'POST') fputs($fp, "Content-length: ". strlen($data) ."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
if ($method == 'POST') fputs($fp, $data);
$result = '';
while(!feof($fp)) {
// receive the results of the request
$result .= fgets($fp, 128);
}
} else {
die("$errstr ($errno)");
}
fclose($fp);
$result = explode("\r\n\r\n", $result, 2);
$header = isset($result[0]) ? $result[0] : '';
$content = isset($result[1]) ? $result[1] : '';
return array(
'status' => 'ok',
'header' => $header,
'content' => $content
);
}
?>