blob: 695a650e0ca6236560feb88e74fa8008709622a9 [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001###########
2Input Class
3###########
4
5The Input Class serves two purposes:
6
7#. It pre-processes global input data for security.
Andrey Andreev303eef02012-11-06 14:55:48 +02008#. It provides some helper methods for fetching input data and pre-processing it.
Derek Jones8ede1a22011-10-05 13:34:52 -05009
10.. note:: This class is initialized automatically by the system so there
11 is no need to do it manually.
12
Andrey Andreev04535c72014-01-06 10:57:05 +020013.. contents::
14 :local:
15
16.. raw:: html
17
18 <div class="custom-index container"></div>
19
Derek Jones8ede1a22011-10-05 13:34:52 -050020Security Filtering
21==================
22
Andrey Andreev303eef02012-11-06 14:55:48 +020023The security filtering method is called automatically when a new
Derek Jones8ede1a22011-10-05 13:34:52 -050024:doc:`controller <../general/controllers>` is invoked. It does the
25following:
26
Andrey Andreev04535c72014-01-06 10:57:05 +020027- If ``$config['allow_get_array']`` is FALSE (default is TRUE), destroys
Derek Jones8ede1a22011-10-05 13:34:52 -050028 the global GET array.
29- Destroys all global variables in the event register_globals is
30 turned on.
31- Filters the GET/POST/COOKIE array keys, permitting only alpha-numeric
32 (and a few other) characters.
33- Provides XSS (Cross-site Scripting Hacks) filtering. This can be
34 enabled globally, or upon request.
Andrey Andreevbfb635b2014-01-08 18:32:05 +020035- Standardizes newline characters to ``PHP_EOL`` (\\n in UNIX-based OSes,
36 \\r\\n under Windows). This is configurable.
Derek Jones8ede1a22011-10-05 13:34:52 -050037
38XSS Filtering
39=============
40
41The Input class has the ability to filter input automatically to prevent
42cross-site scripting attacks. If you want the filter to run
43automatically every time it encounters POST or COOKIE data you can
Andrey Andreev04535c72014-01-06 10:57:05 +020044enable it by opening your *application/config/config.php* file and setting
Derek Jones8ede1a22011-10-05 13:34:52 -050045this::
46
47 $config['global_xss_filtering'] = TRUE;
48
49Please refer to the :doc:`Security class <security>` documentation for
50information on using XSS Filtering in your application.
51
Andrey Andreev9cf12d12012-06-13 10:19:59 +030052Using POST, GET, COOKIE, or SERVER Data
53=======================================
Derek Jones8ede1a22011-10-05 13:34:52 -050054
Andrey Andreev04535c72014-01-06 10:57:05 +020055CodeIgniter comes with helper methods that let you fetch POST, GET,
Derek Jones8ede1a22011-10-05 13:34:52 -050056COOKIE or SERVER items. The main advantage of using the provided
Andrey Andreev303eef02012-11-06 14:55:48 +020057methods rather than fetching an item directly (``$_POST['something']``)
Andrey Andreev9cf12d12012-06-13 10:19:59 +030058is that the methods will check to see if the item is set and return
59NULL if not. This lets you conveniently use data without
Derek Jones8ede1a22011-10-05 13:34:52 -050060having to test whether an item exists first. In other words, normally
61you might do something like this::
62
Phil Sturgeon55a6ddb2012-05-23 18:37:24 +010063 $something = isset($_POST['something']) ? $_POST['something'] : NULL;
Derek Jones8ede1a22011-10-05 13:34:52 -050064
Andrey Andreev303eef02012-11-06 14:55:48 +020065With CodeIgniter's built in methods you can simply do this::
Derek Jones8ede1a22011-10-05 13:34:52 -050066
67 $something = $this->input->post('something');
68
Andrey Andreev04535c72014-01-06 10:57:05 +020069The main methods are:
Derek Jones8ede1a22011-10-05 13:34:52 -050070
Andrey Andreev28c2c972014-02-08 04:27:48 +020071- ``$this->input->post()``
72- ``$this->input->get()``
73- ``$this->input->cookie()``
74- ``$this->input->server()``
Derek Jones8ede1a22011-10-05 13:34:52 -050075
Andrey Andreev303eef02012-11-06 14:55:48 +020076Using the php://input stream
77============================
78
79If you want to utilize the PUT, DELETE, PATCH or other exotic request
80methods, they can only be accessed via a special input stream, that
81can only be read once. This isn't as easy as just reading from e.g.
82the ``$_POST`` array, because it will always exist and you can try
83and access multiple variables without caring that you might only have
84one shot at all of the POST data.
85
86CodeIgniter will take care of that for you, and you can access data
87from the **php://input** stream at any time, just by calling the
88``input_stream()`` method::
89
90 $this->input->input_stream('key');
91
Andrey Andreev04535c72014-01-06 10:57:05 +020092Similar to other methods such as ``get()`` and ``post()``, if the
93requested data is not found, it will return NULL and you can also
94decide whether to run the data through ``xss_clean()`` by passing
95a boolean value as the second parameter::
Andrey Andreev303eef02012-11-06 14:55:48 +020096
97 $this->input->input_stream('key', TRUE); // XSS Clean
98 $this->input->input_stream('key', FALSE); // No XSS filter
99
Andrey Andreev04535c72014-01-06 10:57:05 +0200100.. note:: You can utilize ``method()`` in order to know if you're reading
Andrey Andreev303eef02012-11-06 14:55:48 +0200101 PUT, DELETE or PATCH data.
102
Andrey Andreev04535c72014-01-06 10:57:05 +0200103***************
104Class Reference
105***************
Derek Jones8ede1a22011-10-05 13:34:52 -0500106
Andrey Andreev04535c72014-01-06 10:57:05 +0200107.. class:: CI_Input
Derek Jones8ede1a22011-10-05 13:34:52 -0500108
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200109 .. method:: post([$index = NULL[, $xss_clean = NULL]])
Derek Jones8ede1a22011-10-05 13:34:52 -0500110
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200111 :param mixed $index: POST parameter name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200112 :param bool $xss_clean: Whether to apply XSS filtering
113 :returns: $_POST if no parameters supplied, otherwise the POST value if found or NULL if not
114 :rtype: mixed
Derek Jones8ede1a22011-10-05 13:34:52 -0500115
Andrey Andreev04535c72014-01-06 10:57:05 +0200116 The first parameter will contain the name of the POST item you are
117 looking for::
Derek Jones8831d112011-10-05 15:57:02 -0500118
Andrey Andreev04535c72014-01-06 10:57:05 +0200119 $this->input->post('some_data');
Derek Jones8ede1a22011-10-05 13:34:52 -0500120
Andrey Andreev04535c72014-01-06 10:57:05 +0200121 The method returns NULL if the item you are attempting to retrieve
122 does not exist.
Derek Jones8ede1a22011-10-05 13:34:52 -0500123
Andrey Andreev04535c72014-01-06 10:57:05 +0200124 The second optional parameter lets you run the data through the XSS
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200125 filter. It's enabled by setting the second parameter to boolean TRUE
126 or by setting your ``$config['global_xss_filtering']`` to TRUE.
Andrey Andreev04535c72014-01-06 10:57:05 +0200127 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500128
Andrey Andreev04535c72014-01-06 10:57:05 +0200129 $this->input->post('some_data', TRUE);
Derek Jones8ede1a22011-10-05 13:34:52 -0500130
Andrey Andreev04535c72014-01-06 10:57:05 +0200131 To return an array of all POST items call without any parameters.
Derek Jones8ede1a22011-10-05 13:34:52 -0500132
Andrey Andreev04535c72014-01-06 10:57:05 +0200133 To return all POST items and pass them through the XSS filter set the
134 first parameter NULL while setting the second parameter to boolean TRUE.
135 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500136
Andrey Andreev04535c72014-01-06 10:57:05 +0200137 $this->input->post(NULL, TRUE); // returns all POST items with XSS filter
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200138 $this->input->post(NULL, FALSE); // returns all POST items without XSS filter
David Wosnitzad31a4e62014-12-12 16:35:35 +0100139
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200140 To return an array of multiple POST parameters, pass all the required keys
141 as an array.
142 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100143
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200144 $this->input->post(array('field1', 'field2'));
David Wosnitzad31a4e62014-12-12 16:35:35 +0100145
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200146 Same rule applied here, to retrive the parameters with XSS filtering enabled, set the
147 second parameter to boolean TRUE.
148 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100149
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200150 $this->input->post(array('field1', 'field2'), TRUE);
Derek Jones8ede1a22011-10-05 13:34:52 -0500151
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200152 .. method:: get([$index = NULL[, $xss_clean = NULL]])
Derek Jones8ede1a22011-10-05 13:34:52 -0500153
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200154 :param mixed $index: GET parameter name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200155 :param bool $xss_clean: Whether to apply XSS filtering
156 :returns: $_GET if no parameters supplied, otherwise the GET value if found or NULL if not
157 :rtype: mixed
Derek Jones8ede1a22011-10-05 13:34:52 -0500158
Andrey Andreev04535c72014-01-06 10:57:05 +0200159 This method is identical to ``post()``, only it fetches GET data.
160 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500161
Andrey Andreev04535c72014-01-06 10:57:05 +0200162 $this->input->get('some_data', TRUE);
163
164 To return an array of all GET items call without any parameters.
165
166 To return all GET items and pass them through the XSS filter set the
167 first parameter NULL while setting the second parameter to boolean TRUE.
168 ::
169
170 $this->input->get(NULL, TRUE); // returns all GET items with XSS filter
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200171 $this->input->get(NULL, FALSE); // returns all GET items without XSS filtering
David Wosnitzad31a4e62014-12-12 16:35:35 +0100172
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200173 To return an array of multiple GET parameters, pass all the required keys
174 as an array.
175 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100176
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200177 $this->input->get(array('field1', 'field2'));
David Wosnitzad31a4e62014-12-12 16:35:35 +0100178
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200179 Same rule applied here, to retrive the parameters with XSS filtering enabled, set the
180 second parameter to boolean TRUE.
181 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100182
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200183 $this->input->get(array('field1', 'field2'), TRUE);
Andrey Andreev04535c72014-01-06 10:57:05 +0200184
Andrey Andreev7c60b122014-02-08 18:47:19 +0200185 .. method:: post_get($index[, $xss_clean = NULL])
Andrey Andreevea801ab2014-01-20 15:03:43 +0200186
Andrey Andreev28c2c972014-02-08 04:27:48 +0200187 :param string $index: POST/GET parameter name
188 :param bool $xss_clean: Whether to apply XSS filtering
189 :returns: POST/GET value if found, NULL if not
190 :rtype: mixed
Andrey Andreevea801ab2014-01-20 15:03:43 +0200191
Andrey Andreev7c60b122014-02-08 18:47:19 +0200192 This method works pretty much the same way as ``post()`` and ``get()``,
193 only combined. It will search through both POST and GET streams for data,
194 looking in POST first, and then in GET::
Andrey Andreevea801ab2014-01-20 15:03:43 +0200195
196 $this->input->post_get('some_data', TRUE);
197
Andrey Andreev7c60b122014-02-08 18:47:19 +0200198 .. method:: get_post($index[, $xss_clean = NULL])
Andrey Andreev04535c72014-01-06 10:57:05 +0200199
Andrey Andreev28c2c972014-02-08 04:27:48 +0200200 :param string $index: GET/POST parameter name
201 :param bool $xss_clean: Whether to apply XSS filtering
202 :returns: GET/POST value if found, NULL if not
203 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200204
Andrey Andreevea801ab2014-01-20 15:03:43 +0200205 This method works the same way as ``post_get()`` only it looks for GET
206 data first.
Andrey Andreev04535c72014-01-06 10:57:05 +0200207
208 $this->input->get_post('some_data', TRUE);
209
Andrey Andreevea801ab2014-01-20 15:03:43 +0200210 .. note:: This method used to act EXACTLY like ``post_get()``, but it's
211 behavior has changed in CodeIgniter 3.0.
212
Andrey Andreev7c60b122014-02-08 18:47:19 +0200213 .. method:: cookie([$index = NULL[, $xss_clean = NULL]])
Andrey Andreev04535c72014-01-06 10:57:05 +0200214
Andrey Andreevef29f832014-12-02 18:03:47 +0200215 :param mixed $index: COOKIE name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200216 :param bool $xss_clean: Whether to apply XSS filtering
217 :returns: $_COOKIE if no parameters supplied, otherwise the COOKIE value if found or NULL if not
218 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200219
220 This method is identical to ``post()`` and ``get()``, only it fetches cookie
221 data::
222
223 $this->input->cookie('some_cookie');
224 $this->input->cookie('some_cookie, TRUE); // with XSS filter
David Wosnitzad31a4e62014-12-12 16:35:35 +0100225
Andrey Andreevef29f832014-12-02 18:03:47 +0200226 To return an array of multiple cookie values, pass all the required keys
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200227 as an array.
228 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100229
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200230 $this->input->cookie(array('some_cookie', 'some_cookie2'));
Andrey Andreev04535c72014-01-06 10:57:05 +0200231
Andrey Andreev7c60b122014-02-08 18:47:19 +0200232 .. method:: server($index[, $xss_clean = NULL])
Andrey Andreev04535c72014-01-06 10:57:05 +0200233
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200234 :param mixed $index: Value name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200235 :param bool $xss_clean: Whether to apply XSS filtering
236 :returns: $_SERVER item value if found, NULL if not
237 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200238
Andrey Andreev7c60b122014-02-08 18:47:19 +0200239 This method is identical to the ``post()``, ``get()`` and ``cookie()``
240 methods, only it fetches server data (``$_SERVER``)::
Andrey Andreev04535c72014-01-06 10:57:05 +0200241
242 $this->input->server('some_data');
243
Andrey Andreevef29f832014-12-02 18:03:47 +0200244 To return an array of multiple ``$_SERVER`` values, pass all the required keys
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200245 as an array.
246 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100247
248 $this->input->server(array('SERVER_PROTOCOL', 'REQUEST_URI'));
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200249
Andrey Andreev7c60b122014-02-08 18:47:19 +0200250 .. method:: input_stream([$index = NULL[, $xss_clean = NULL]])
Andrey Andreev04535c72014-01-06 10:57:05 +0200251
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200252 :param mixed $index: Key name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200253 :param bool $xss_clean: Whether to apply XSS filtering
254 :returns: Input stream array if no parameters supplied, otherwise the specified value if found or NULL if not
255 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200256
257 This method is identical to ``get()``, ``post()`` and ``cookie()``,
258 only it fetches the *php://input* stream data.
259
260 .. method:: set_cookie($name = ''[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = FALSE[, $httponly = FALSE]]]]]]])
261
Andrey Andreev28c2c972014-02-08 04:27:48 +0200262 :param mixed $name: Cookie name or an array of parameters
263 :param string $value: Cookie value
264 :param int $expire: Cookie expiration time in seconds
265 :param string $domain: Cookie domain
266 :param string $path: Cookie path
267 :param string $prefix: Cookie name prefix
268 :param bool $secure: Whether to only transfer the cookie through HTTPS
269 :param bool $httponly: Whether to only make the cookie accessible for HTTP requests (no JavaScript)
270 :rtype: void
271
Andrey Andreev04535c72014-01-06 10:57:05 +0200272
273 Sets a cookie containing the values you specify. There are two ways to
274 pass information to this method so that a cookie can be set: Array
275 Method, and Discrete Parameters:
276
Connor Tumbleson75b3fb22014-01-11 06:58:43 -0600277 **Array Method**
Andrey Andreev04535c72014-01-06 10:57:05 +0200278
279 Using this method, an associative array is passed to the first
280 parameter::
281
282 $cookie = array(
283 'name' => 'The Cookie Name',
284 'value' => 'The Value',
285 'expire' => '86500',
286 'domain' => '.some-domain.com',
287 'path' => '/',
288 'prefix' => 'myprefix_',
289 'secure' => TRUE
290 );
291
292 $this->input->set_cookie($cookie);
293
Andrey Andreev28c2c972014-02-08 04:27:48 +0200294 **Notes**
Andrey Andreev04535c72014-01-06 10:57:05 +0200295
296 Only the name and value are required. To delete a cookie set it with the
297 expiration blank.
298
299 The expiration is set in **seconds**, which will be added to the current
300 time. Do not include the time, but rather only the number of seconds
301 from *now* that you wish the cookie to be valid. If the expiration is
302 set to zero the cookie will only last as long as the browser is open.
303
304 For site-wide cookies regardless of how your site is requested, add your
305 URL to the **domain** starting with a period, like this:
306 .your-domain.com
307
308 The path is usually not needed since the method sets a root path.
309
310 The prefix is only needed if you need to avoid name collisions with
311 other identically named cookies for your server.
312
313 The secure boolean is only needed if you want to make it a secure cookie
314 by setting it to TRUE.
315
Connor Tumbleson75b3fb22014-01-11 06:58:43 -0600316 **Discrete Parameters**
Andrey Andreev04535c72014-01-06 10:57:05 +0200317
318 If you prefer, you can set the cookie by passing data using individual
319 parameters::
320
321 $this->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure);
Derek Jones8ede1a22011-10-05 13:34:52 -0500322
Andrey Andreev04535c72014-01-06 10:57:05 +0200323 .. method:: ip_address()
Derek Jones8ede1a22011-10-05 13:34:52 -0500324
Andrey Andreev28c2c972014-02-08 04:27:48 +0200325 :returns: Visitor's IP address or '0.0.0.0' if not valid
326 :rtype: string
Derek Jones8ede1a22011-10-05 13:34:52 -0500327
Andrey Andreev04535c72014-01-06 10:57:05 +0200328 Returns the IP address for the current user. If the IP address is not
329 valid, the method will return '0.0.0.0'::
Derek Jones8ede1a22011-10-05 13:34:52 -0500330
Andrey Andreev04535c72014-01-06 10:57:05 +0200331 echo $this->input->ip_address();
Derek Jones8ede1a22011-10-05 13:34:52 -0500332
Andrey Andreev04535c72014-01-06 10:57:05 +0200333 .. important:: This method takes into account the ``$config['proxy_ips']``
334 setting and will return the reported HTTP_X_FORWARDED_FOR,
335 HTTP_CLIENT_IP, HTTP_X_CLIENT_IP or HTTP_X_CLUSTER_CLIENT_IP
336 address for the allowed IP addresses.
Derek Jones8ede1a22011-10-05 13:34:52 -0500337
Andrey Andreev04535c72014-01-06 10:57:05 +0200338 .. method:: valid_ip($ip[, $which = ''])
Andrey Andreev303eef02012-11-06 14:55:48 +0200339
Andrey Andreev28c2c972014-02-08 04:27:48 +0200340 :param string $ip: IP address
341 :param string $which: IP protocol ('ipv4' or 'ipv6')
342 :returns: TRUE if the address is valid, FALSE if not
343 :rtype: bool
Derek Jones8ede1a22011-10-05 13:34:52 -0500344
Andrey Andreev04535c72014-01-06 10:57:05 +0200345 Takes an IP address as input and returns TRUE or FALSE (boolean) depending
346 on whether it is valid or not.
Derek Jones8ede1a22011-10-05 13:34:52 -0500347
Andrey Andreev04535c72014-01-06 10:57:05 +0200348 .. note:: The $this->input->ip_address() method above automatically
349 validates the IP address.
Derek Jones8ede1a22011-10-05 13:34:52 -0500350
Andrey Andreev04535c72014-01-06 10:57:05 +0200351 ::
Andrey Andreev5a257182012-06-10 06:18:14 +0300352
Andrey Andreev04535c72014-01-06 10:57:05 +0200353 if ( ! $this->input->valid_ip($ip))
354 {
355 echo 'Not Valid';
356 }
357 else
358 {
359 echo 'Valid';
360 }
Derek Jones8ede1a22011-10-05 13:34:52 -0500361
Andrey Andreev04535c72014-01-06 10:57:05 +0200362 Accepts an optional second string parameter of 'ipv4' or 'ipv6' to specify
363 an IP format. The default checks for both formats.
Derek Jones8ede1a22011-10-05 13:34:52 -0500364
Andrey Andreev8850e372014-02-27 21:56:06 +0200365 .. method:: user_agent([$xss_clean = NULL])
Derek Jones8ede1a22011-10-05 13:34:52 -0500366
Andrey Andreev28c2c972014-02-08 04:27:48 +0200367 :returns: User agent string or NULL if not set
Andrey Andreev8850e372014-02-27 21:56:06 +0200368 :param bool $xss_clean: Whether to apply XSS filtering
Andrey Andreev28c2c972014-02-08 04:27:48 +0200369 :rtype: mixed
Derek Jones8ede1a22011-10-05 13:34:52 -0500370
Andrey Andreev04535c72014-01-06 10:57:05 +0200371 Returns the user agent string (web browser) being used by the current user,
372 or NULL if it's not available.
373 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500374
Andrey Andreev04535c72014-01-06 10:57:05 +0200375 echo $this->input->user_agent();
Derek Jones8ede1a22011-10-05 13:34:52 -0500376
Andrey Andreev04535c72014-01-06 10:57:05 +0200377 See the :doc:`User Agent Class <user_agent>` for methods which extract
378 information from the user agent string.
Derek Jones8ede1a22011-10-05 13:34:52 -0500379
Andrey Andreev04535c72014-01-06 10:57:05 +0200380 .. method:: request_headers([$xss_clean = FALSE])
Derek Jones8ede1a22011-10-05 13:34:52 -0500381
Andrey Andreev28c2c972014-02-08 04:27:48 +0200382 :param bool $xss_clean: Whether to apply XSS filtering
383 :returns: An array of HTTP request headers
384 :rtype: array
Derek Jones8ede1a22011-10-05 13:34:52 -0500385
Andrey Andreev04535c72014-01-06 10:57:05 +0200386 Returns an array of HTTP request headers.
387 Useful if running in a non-Apache environment where
388 `apache_request_headers() <http://php.net/apache_request_headers>`_
389 will not be supported.
390 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500391
Andrey Andreev04535c72014-01-06 10:57:05 +0200392 $headers = $this->input->request_headers();
Derek Jones8ede1a22011-10-05 13:34:52 -0500393
Andrey Andreev04535c72014-01-06 10:57:05 +0200394 .. method:: get_request_header($index[, $xss_clean = FALSE])
Derek Jones8ede1a22011-10-05 13:34:52 -0500395
Andrey Andreev28c2c972014-02-08 04:27:48 +0200396 :param string $index: HTTP request header name
397 :param bool $xss_clean: Whether to apply XSS filtering
398 :returns: An HTTP request header or NULL if not found
399 :rtype: string
Derek Jones8ede1a22011-10-05 13:34:52 -0500400
Andrey Andreev04535c72014-01-06 10:57:05 +0200401 Returns a single member of the request headers array or NULL
402 if the searched header is not found.
403 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500404
Andrey Andreev04535c72014-01-06 10:57:05 +0200405 $this->input->get_request_header('some-header', TRUE);
Derek Jones8ede1a22011-10-05 13:34:52 -0500406
Andrey Andreev04535c72014-01-06 10:57:05 +0200407 .. method:: is_ajax_request()
Derek Jones8ede1a22011-10-05 13:34:52 -0500408
Andrey Andreev28c2c972014-02-08 04:27:48 +0200409 :returns: TRUE if it is an Ajax request, FALSE if not
410 :rtype: bool
Derek Jones8ede1a22011-10-05 13:34:52 -0500411
Andrey Andreev04535c72014-01-06 10:57:05 +0200412 Checks to see if the HTTP_X_REQUESTED_WITH server header has been
413 set, and returns boolean TRUE if it is or FALSE if not.
Derek Jones8ede1a22011-10-05 13:34:52 -0500414
Andrey Andreev04535c72014-01-06 10:57:05 +0200415 .. method:: is_cli_request()
Derek Jones8ede1a22011-10-05 13:34:52 -0500416
Andrey Andreev28c2c972014-02-08 04:27:48 +0200417 :returns: TRUE if it is a CLI request, FALSE if not
418 :rtype: bool
Michiel Vugteveenbe0ca262012-03-07 19:09:51 +0100419
Andrey Andreev04535c72014-01-06 10:57:05 +0200420 Checks to see if the application was run from the command-line
421 interface.
Michiel Vugteveenbe0ca262012-03-07 19:09:51 +0100422
Andrey Andreev04535c72014-01-06 10:57:05 +0200423 .. note:: This method checks both the PHP SAPI name currently in use
424 and if the ``STDIN`` constant is defined, which is usually a
425 failsafe way to see if PHP is being run via the command line.
Michiel Vugteveenbe0ca262012-03-07 19:09:51 +0100426
Andrey Andreev04535c72014-01-06 10:57:05 +0200427 ::
428
429 $this->input->is_cli_request()
430
Andrey Andreevea801ab2014-01-20 15:03:43 +0200431 .. note:: This method is DEPRECATED and is now just an alias for the
432 :func:`is_cli()` function.
433
Andrey Andreev04535c72014-01-06 10:57:05 +0200434 .. method:: method([$upper = FALSE])
435
Andrey Andreev28c2c972014-02-08 04:27:48 +0200436 :param bool $upper: Whether to return the request method name in upper or lower case
437 :returns: HTTP request method
438 :rtype: string
Andrey Andreev04535c72014-01-06 10:57:05 +0200439
440 Returns the ``$_SERVER['REQUEST_METHOD']``, with the option to set it
441 in uppercase or lowercase.
442 ::
443
444 echo $this->input->method(TRUE); // Outputs: POST
445 echo $this->input->method(FALSE); // Outputs: post
David Wosnitzad31a4e62014-12-12 16:35:35 +0100446 echo $this->input->method(); // Outputs: post