diff --git a/modules/farm/farm_access/farm_access.module b/modules/farm/farm_access/farm_access.module index 84f221aef..b615d8873 100644 --- a/modules/farm/farm_access/farm_access.module +++ b/modules/farm/farm_access/farm_access.module @@ -26,6 +26,25 @@ function farm_access_init() { } } +/** + * If getallheaders() is not available, implement it ourselves. + * + * This is necessary in PHP CLI and Nginx contexts. + * See https://github.com/farmOS/farmOS/issues/271#issuecomment-663543706 + * + * Code is taken from http://php.net/manual/en/function.getallheaders.php + */ +if (!function_exists('getallheaders')) { + function getallheaders() { + foreach ($_SERVER as $name => $value) { + if (substr($name, 0, 5) == 'HTTP_') { + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; + } + } + return $headers; + } +} + /** * Implements hook_hook_info(). */