You are here

public static function Helper::http__get_headers in Anti Spam by CleanTalk 9.1.x

Same name and namespace in other branches
  1. 8.4 src/lib/Cleantalk/Common/Helper.php \Cleantalk\Common\Helper::http__get_headers()

Gets every HTTP_ headers from $_SERVER

If Apache web server is missing then making Patch for apache_request_headers()

@todo Have to replace this method to the new class like HttpHelper

Return value

array

1 call to Helper::http__get_headers()
Helper::ip__get in src/lib/Cleantalk/Common/Helper.php
Getting arrays of IP (REMOTE_ADDR, X-Forwarded-For, X-Real-Ip, Cf_Connecting_Ip)

File

src/lib/Cleantalk/Common/Helper.php, line 1255

Class

Helper
CleanTalk Helper class. Compatible with any CMS.

Namespace

Cleantalk\Common

Code

public static function http__get_headers() {
  $headers = array();
  foreach ($_SERVER as $key => $val) {
    if (0 === stripos($key, 'http_')) {
      $server_key = preg_replace('/^http_/i', '', $key);
      $key_parts = explode('_', $server_key);
      if (count($key_parts) > 0 and strlen($server_key) > 2) {
        foreach ($key_parts as $part_index => $part) {
          if (!empty($part)) {
            $key_parts[$part_index] = function_exists('mb_strtolower') ? mb_strtolower($part) : strtolower($part);
            $key_parts[$part_index][0] = strtoupper($key_parts[$part_index][0]);
          }
        }
        $server_key = implode('-', $key_parts);
      }
      $headers[$server_key] = $val;
    }
  }
  return $headers;
}