-
-
Save Mythli/ee2ee76030245e0121f4778d7b814f63 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 | |
if (!function_exists('getallheaders')) { | |
function getallheaders() | |
{ | |
$headers = []; | |
foreach ($_SERVER as $name => $value) { | |
if (substr($name, 0, 5) == 'HTTP_') { | |
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; | |
} | |
} | |
return $headers; | |
} | |
} | |
function get_header( $pHeaderKey ) | |
{ | |
$serverHeaders = getallheaders(); | |
foreach($serverHeaders as $key => $value) { | |
if(strcasecmp($key, $pHeaderKey) === 0) { return $value; } | |
} | |
return null; | |
} | |
// Change these configuration options if needed, see above descriptions for info. | |
$enable_jsonp = false; | |
$enable_native = true; | |
$valid_url_regex = '/https:\\/\\/TODO_PUT_INSTALLATION_NAME_HERE\\.veranstaltungsbutler\\.de.*/'; | |
// ############################################################################ | |
$url = $_GET['url']; | |
$forwardedHeaders = ['Content-Length', 'Content-Type', 'Cache-Control', 'User-Agent', 'Accept-Language', 'Accept']; | |
$headers = []; | |
foreach($forwardedHeaders as $forwardedHeader) { | |
if(!strlen(get_header($forwardedHeader))) { | |
continue; | |
} | |
$headers[] = $forwardedHeader.': '.get_header($forwardedHeader); | |
} | |
if ( !$url ) { | |
// Passed url not specified. | |
$contents = 'ERROR: url not specified'; | |
$status = array( 'http_code' => 'ERROR' ); | |
} else if ( !preg_match( $valid_url_regex, $url ) ) { | |
// Passed url doesn't match $valid_url_regex. | |
$contents = 'ERROR: invalid url'; | |
$status = array( 'http_code' => 'ERROR' ); | |
} else { | |
$ch = curl_init( $url ); | |
if ( strtolower($_SERVER['REQUEST_METHOD']) == 'post' ) { | |
curl_setopt( $ch, CURLOPT_POST, true ); | |
$entityBody = file_get_contents('php://input'); | |
curl_setopt( $ch, CURLOPT_POSTFIELDS, $entityBody ); | |
} | |
if ( $_GET['send_cookies'] ) { | |
$cookie = array(); | |
foreach ( $_COOKIE as $key => $value ) { | |
$cookie[] = $key . '=' . $value; | |
} | |
if ( $_GET['send_session'] ) { | |
$cookie[] = SID; | |
} | |
$cookie = implode( '; ', $cookie ); | |
curl_setopt( $ch, CURLOPT_COOKIE, $cookie ); | |
} | |
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); | |
curl_setopt( $ch, CURLOPT_HEADER, true ); | |
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt( $ch, CURLOPT_USERAGENT, $_GET['user_agent'] ? $_GET['user_agent'] : $_SERVER['HTTP_USER_AGENT'] ); | |
$response = curl_exec($ch); | |
// Then, after your curl_exec call: | |
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); | |
$header = substr($response, 0, $header_size); | |
$body = substr($response, $header_size); | |
$status = curl_getinfo( $ch ); | |
curl_close( $ch ); | |
} | |
// Split header text into an array. | |
$header_text = preg_split( '/[\r\n]+/', $header ); | |
// Propagate headers to response. | |
foreach ( $header_text as $header ) { | |
if ( preg_match( '/^(?:Content-Type|Content-Language|Set-Cookie|ETag|Last-Modified):/i', $header ) ) { | |
header( $header ); | |
} | |
} | |
print $body; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment