Files
2019-05-25 23:11:05 -04:00

54 lines
1.5 KiB
PHP

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$in = $_POST;
$out = array();
external_internal_call($in, $out);
//NOTE
//$out['internal_return'] = $ret;
// this is reserved array parameter - to be caprured and reoved before you use the out array()
foreach ($out as $key => $value) {
echo $key . "=" . base64_encode($value) . "\n";
}
} else {
echo "status=" . base64_encode("Invalid request method") . "\n";
}
/*
THIS IS AN EXTERNAL LAYER OF TOTAL SEPARATION
*/
function external_internal_call($in, &$out) {
global $target_url; // "svrlayer/internal.php";
$fields_string = "";
//url-ify the data for the POST
foreach ($in 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, $target_url);
curl_setopt($ch, CURLOPT_POST, count($in));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
// Parse result
foreach (explode("\n", $result) as $line) {
if ($line == "" || strpos($line, "=") === false)
continue;
$key = trim(strtok($line, "="));
if ($key != "") {
$out[$key] = base64_decode(substr($line, 1 + strlen($key)));
}
}
}