From 067c45db9ded7f6d20f144833f235f62d0838fc0 Mon Sep 17 00:00:00 2001 From: Andrew Munro Date: Tue, 10 Nov 2015 14:36:27 +0000 Subject: [PATCH] Adding platform agnostic way to fetch all request headers. --- app/main/controller/controller.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/main/controller/controller.php b/app/main/controller/controller.php index aebff018..65c9c4f1 100644 --- a/app/main/controller/controller.php +++ b/app/main/controller/controller.php @@ -175,7 +175,7 @@ class Controller { $data = (object) []; $data->trusted = false; $data->values = []; - $headerData = apache_request_headers(); + $headerData = self::getRequestHeaders(); foreach($headerData as $key => $value){ $key = strtolower($key); @@ -199,6 +199,24 @@ class Controller { return $data; } + /** + * Helper function to return all headers because + * getallheaders() is not available under nginx + * + * @return array (string $key -> string $value) + */ + static function getRequestHeaders(){ + $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; + } + /** * check if the current request was send from inGame * @return bool