Created
August 21, 2014 20:05
-
-
Save alkrauss48/2e94bada532e977f6418 to your computer and use it in GitHub Desktop.
Server Side Request Forwarder - accepts client side post requests and submits them to the real destination server side
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 | |
// Assuming a POST to this script in form of: | |
// request_forwarder?url=url_name | |
// | |
// This will convert a client side AJAX request to a server side PHP curl, | |
// thus eleminating worries of cross-site scripting and having to abide by | |
// cross-origin-request-sharing (CORS) settings on the end server. | |
$url = $_GET['url']; | |
$fields_string = ''; | |
//url-ify the data for the POST | |
foreach($_POST as $key=>$value) { | |
$fields_string .= $key . '=' . $value . '&'; | |
} | |
rtrim($fields_string, '&'); | |
//open connection | |
$ch = curl_init(); | |
//set the url, number of POST vars, POST data | |
curl_setopt($ch,CURLOPT_URL, $url); | |
curl_setopt($ch,CURLOPT_POST, count($_POST)); | |
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); | |
//execute post | |
$result = curl_exec($ch); | |
//close connection | |
curl_close($ch); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe it would be cool to add some HTTP_X_FORWARDED headers for scripts that require the user's IP-address?