Exemplo n.º 1
0
	static function request_by_file($url, $method, $data){
		  if(is_array($data)){
			  $data = http_build_query($data, '', '&');
		  }
		 $ctx = array (
			'http' => array (
				'method' => strtoupper($method),
				'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
					. "Content-Length: " . strlen($data) . "\r\n",
				'content' => $data
			)
		);
       $context = stream_context_create($ctx);
       return file_get_contents($url,false,$context);
	}
}

//entry point
$resource = isset($_REQUEST['resource']) ? $_REQUEST['resource'] : '';
if($resource == ''){
	exit(0);
}
$method = $_SERVER['REQUEST_METHOD'];
$data =  strtolower($method) == 'post' ? $_POST: $_GET;

if(function_exists('file_get_contents')){
	echo Proxy::request_by_file($resource, $method, $data);
}else if(function_exists('curl_init')){
	echo Proxy::request_by_curl($resource, $method, $data);
}
?>