How to get HTTP header information in CI:
$this->input->request_headers ()
is useful in non-Apache environments that do not support apache_request_headers (). Returns an array of header (header) requests.
$headers = $this->input->request_headers();
----------------------------------------------------------------------------------------------
Gets the header information for the HTTP request.
The PHP manual provides ready-made functions:
Getallheaders
(PHP 4, PHP 5)
getallheaders- Fetch All HTTP request Headers
Descriptionarray
getallheaders ( void)
Fetches all HTTP headers from the current request.
This function is a alias for Apache_request_headers (). Please read theapache_request_headers () documentation For more information in how this function works.
return value
An associative array of any the HTTP headers in the current request, orFALSE on failure.
Example #1 getallheaders () Example
[PHP]View Plaincopy
- <?php
- foreach (getallheaders () as $name = = $value) {
- echo "$name: $value \ n";
- }
- ?>
However, this function can only be used in Apache environment, IIS or Nginx is not supported, can be implemented by custom functions
[PHP]View Plaincopy
- <?php
- <span class="html" >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;
- }
- }</span>
- ?>
All right, let's see what's printed out.
[PHP]View Plaincopy
- <?php
- Print_r (getallheaders ());
Get results:
[HTML]View Plaincopy
- ARRAY&NBSP;&NBSP;
- (
- > */*
- [accept-language] => zh-cn
- > gzip, deflate
- [user-agent] => mozilla/4.0 ( compatible; msie 7.0; windows nt 5.1; trident/4.0; .net clr 2.0.50727)
- [host] => localhost
- [connection] => keep-alive
-
-
PHP gets HTTP header information and how to get HTTP header information in CI