Headers

A Slim application will automatically parse all HTTP request headers. You can access the request headers using therequest object’s public headers property. The headers property is an instance of \Slim\Helper\Set, meaningit provides a simple, standardized interface to interactive with the HTTP request headers.

  1. <?php
  2. $app = new \Slim\Slim();
  3. // Get request headers as associative array
  4. $headers = $app->request->headers;
  5. // Get the ACCEPT_CHARSET header
  6. $charset = $app->request->headers->get('ACCEPT_CHARSET');

The HTTP specification states that HTTP header names may be uppercase, lowercase, or mixed-case. Slim is smart enoughto parse and return header values whether you request a header value using upper, lower, or mixed case header name,with either underscores or dashes. So use the naming convention with which you are most comfortable.