From 03c0f2e80502a6779079be02f2f6062ea6e0131e Mon Sep 17 00:00:00 2001 From: Wruczek Date: Tue, 23 Apr 2019 05:35:38 +0200 Subject: [PATCH] Metrics: Use native functions instead of cURL - better compatibility --- src/installer/pages/7.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/installer/pages/7.php b/src/installer/pages/7.php index 0d89c00..2929629 100644 --- a/src/installer/pages/7.php +++ b/src/installer/pages/7.php @@ -55,17 +55,19 @@ if(!empty($_COOKIE["tsw_allow_metrics"])) { $data = json_encode($data); $url = "https://wruczek.tech/tsw-metrics/"; - // If cURL is available, use it - if (function_exists("curl_version")) { - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $data); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $response = curl_exec($ch); - curl_close($ch); + $options = [ + "http" => [ + "header" => "Content-Type: application/json", + "method" => "POST", + "content" => $data + ] + ]; - //echo $response; + $context = stream_context_create($options); + $response = file_get_contents($url, false, $context); + + if ($response !== "ok") { + echo "Error sending metrics :("; } } ?>