-
-
Save tejastank/1619dba5fdbd81253bab4f96564b9d27 to your computer and use it in GitHub Desktop.
Simple PHP Proxy
This file contains hidden or 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 | |
/** | |
* @author Han Lin Yap < http://zencodez.net/ > | |
* @copyright 2012 zencodez.net | |
* @license http://creativecommons.org/licenses/by-sa/3.0/ | |
* @package proxy | |
* @version 1.0 - 2012-05-01 | |
*/ | |
$method = $_SERVER['REQUEST_METHOD']; | |
$request = substr($_SERVER['PATH_INFO'], 1); | |
$request = str_replace('http:/', 'http://', $request); | |
# Request headers | |
$headers = apache_request_headers(); | |
$header_string = ''; | |
foreach ($headers AS $header => $value) { | |
if (strtolower($header) == 'host') continue; | |
$header_string .= "$header: $value\r\n"; | |
} | |
$opts = array('http' => | |
array( | |
'method' => $method, | |
'header' => $header_string, | |
) | |
); | |
# Request content | |
if ($method == 'GET') { | |
$request .= '?' . http_build_query($_GET); | |
} else { | |
$content = ($method == 'POST') ? http_build_query($_POST) : @file_get_contents('php://input'); | |
$opts['http']['content'] = $content; | |
} | |
# Proxy | |
$result = @file_get_contents($request, false, stream_context_create($opts)); | |
# Response headers | |
foreach ($http_response_header AS $header) { | |
header($header); | |
} | |
# Response content | |
echo $result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment