Not super sexy ( even in this 'nude look' ; - )
<?php
// params v1.1 2020-11-24 added GET forwarder
//
// server to forward the POST data received ( full url including index.php for ecowitt ), leave empty if not used ( used by ECOWITT )
$forward_server_1 = "";
// server to forward the GET data received ( full url ), leave empty if not used ( used by WU, WINDY, AMBIENT... )
//$forward_server_2 = "";
$forward_server_2 = "https://weatherstation.wunderground.com/weatherstation/updateweatherstation.php"; // forward to WU
//$forward_server_2 = "https://stations.windy.com/pws/update/INSERT-YOUR-API-KEY"; // forward to Windy
$logFile = __DIR__."/params.txt";
function emu_getallheaders() {
foreach ($_SERVER as $name => $value)
{
if (substr($name, 0, 5) == 'HTTP_')
{
$name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
$headers[$name] = $value;
} else if ($name == "CONTENT_TYPE") {
$headers["Content-Type"] = $value;
} else if ($name == "CONTENT_LENGTH") {
$headers["Content-Length"] = $value;
}
}
return $headers;
}
$h = emu_getallheaders();
echo date("Y-m-d H:i:s");
echo "<br>headers:<br>\n";
print_r($h);
file_put_contents($logFile, date("Y-m-d H:i:s"), FILE_APPEND);
file_put_contents($logFile, "\nheaders:\n", FILE_APPEND);
file_put_contents($logFile, print_r($h,true), FILE_APPEND);
echo "<br>\nGET params:<br>\n";
print_r($_GET);
file_put_contents($logFile, "GET params:\n", FILE_APPEND);
file_put_contents($logFile, print_r($_GET,true), FILE_APPEND);
echo "<br>\nPOST params:<br>\n";
print_r($_POST);
file_put_contents($logFile, "POST params:\n", FILE_APPEND);
file_put_contents($logFile, print_r($_POST,true), FILE_APPEND);
/*$fields = $_GET; // get fields
$getvars = http_build_query($fields); // build the urlencoded data
echo "<br>";
echo "getvars=$getvars<br>";
$getvars=str_replace("%3A",":",$getvars);
echo "getvars=$getvars<br>";*/
if ($forward_server_1 != "")
{
$url = $forward_server_1;
echo "fw1 POST to -> $url<br>";
$fields = $_POST; // post fields
$postvars = http_build_query($fields); // build the urlencoded data
$postvars=str_replace("%3A",":",$postvars);
$ch = curl_init();
// set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
$result = curl_exec($ch); // execute post
curl_close($ch);
echo "fw1 result=$result<br>";
file_put_contents($logFile, "fw1 result=".$result."\n", FILE_APPEND);
}
if ($forward_server_2 != "")
{
$url = $forward_server_2;
echo "fw2 GET to -> $url<br>";
$wdf = "";
foreach($_GET as $key => $value)
{$wdf .= '&' . $key . '=' . $value;}
$wdf=str_replace(":","%3A",$wdf);
$wdf=str_replace(" ","+",$wdf);
$result = file_get_contents($url . "?" . substr($wdf,1));
file_put_contents($logFile, "fw2 url=".$url . "?" . substr($wdf,1)."\n", FILE_APPEND);
echo "fw2 result=$result<br>";
file_put_contents($logFile, "fw2 result=".$result."\n", FILE_APPEND);
}
http_response_code(200);
?>