blob: 4464e0fdcdf9e72a904326bfba52e7df2023dc16 [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
James L Parry08191be2014-12-20 02:37:13 -080020***************
21Input Filtering
22***************
23
Derek Jones8ede1a22011-10-05 13:34:52 -050024Security Filtering
25==================
26
Andrey Andreev303eef02012-11-06 14:55:48 +020027The security filtering method is called automatically when a new
Derek Jones8ede1a22011-10-05 13:34:52 -050028:doc:`controller <../general/controllers>` is invoked. It does the
29following:
30
Andrey Andreev04535c72014-01-06 10:57:05 +020031- If ``$config['allow_get_array']`` is FALSE (default is TRUE), destroys
Derek Jones8ede1a22011-10-05 13:34:52 -050032 the global GET array.
33- Destroys all global variables in the event register_globals is
34 turned on.
35- Filters the GET/POST/COOKIE array keys, permitting only alpha-numeric
36 (and a few other) characters.
37- Provides XSS (Cross-site Scripting Hacks) filtering. This can be
38 enabled globally, or upon request.
Andrey Andreevbfb635b2014-01-08 18:32:05 +020039- Standardizes newline characters to ``PHP_EOL`` (\\n in UNIX-based OSes,
40 \\r\\n under Windows). This is configurable.
Derek Jones8ede1a22011-10-05 13:34:52 -050041
42XSS Filtering
43=============
44
45The Input class has the ability to filter input automatically to prevent
46cross-site scripting attacks. If you want the filter to run
47automatically every time it encounters POST or COOKIE data you can
Andrey Andreev04535c72014-01-06 10:57:05 +020048enable it by opening your *application/config/config.php* file and setting
Derek Jones8ede1a22011-10-05 13:34:52 -050049this::
50
51 $config['global_xss_filtering'] = TRUE;
52
53Please refer to the :doc:`Security class <security>` documentation for
54information on using XSS Filtering in your application.
55
James L Parry08191be2014-12-20 02:37:13 -080056*******************
57Accessing form data
58*******************
59
Andrey Andreev9cf12d12012-06-13 10:19:59 +030060Using POST, GET, COOKIE, or SERVER Data
61=======================================
Derek Jones8ede1a22011-10-05 13:34:52 -050062
Andrey Andreev04535c72014-01-06 10:57:05 +020063CodeIgniter comes with helper methods that let you fetch POST, GET,
Derek Jones8ede1a22011-10-05 13:34:52 -050064COOKIE or SERVER items. The main advantage of using the provided
Andrey Andreev303eef02012-11-06 14:55:48 +020065methods rather than fetching an item directly (``$_POST['something']``)
Andrey Andreev9cf12d12012-06-13 10:19:59 +030066is that the methods will check to see if the item is set and return
67NULL if not. This lets you conveniently use data without
Derek Jones8ede1a22011-10-05 13:34:52 -050068having to test whether an item exists first. In other words, normally
69you might do something like this::
70
Phil Sturgeon55a6ddb2012-05-23 18:37:24 +010071 $something = isset($_POST['something']) ? $_POST['something'] : NULL;
Derek Jones8ede1a22011-10-05 13:34:52 -050072
Andrey Andreev303eef02012-11-06 14:55:48 +020073With CodeIgniter's built in methods you can simply do this::
Derek Jones8ede1a22011-10-05 13:34:52 -050074
75 $something = $this->input->post('something');
76
Andrey Andreev04535c72014-01-06 10:57:05 +020077The main methods are:
Derek Jones8ede1a22011-10-05 13:34:52 -050078
Andrey Andreev28c2c972014-02-08 04:27:48 +020079- ``$this->input->post()``
80- ``$this->input->get()``
81- ``$this->input->cookie()``
82- ``$this->input->server()``
Derek Jones8ede1a22011-10-05 13:34:52 -050083
Andrey Andreev303eef02012-11-06 14:55:48 +020084Using the php://input stream
85============================
86
87If you want to utilize the PUT, DELETE, PATCH or other exotic request
88methods, they can only be accessed via a special input stream, that
89can only be read once. This isn't as easy as just reading from e.g.
90the ``$_POST`` array, because it will always exist and you can try
91and access multiple variables without caring that you might only have
92one shot at all of the POST data.
93
94CodeIgniter will take care of that for you, and you can access data
95from the **php://input** stream at any time, just by calling the
96``input_stream()`` method::
97
98 $this->input->input_stream('key');
99
Andrey Andreev04535c72014-01-06 10:57:05 +0200100Similar to other methods such as ``get()`` and ``post()``, if the
101requested data is not found, it will return NULL and you can also
102decide whether to run the data through ``xss_clean()`` by passing
103a boolean value as the second parameter::
Andrey Andreev303eef02012-11-06 14:55:48 +0200104
105 $this->input->input_stream('key', TRUE); // XSS Clean
106 $this->input->input_stream('key', FALSE); // No XSS filter
107
Andrey Andreev04535c72014-01-06 10:57:05 +0200108.. note:: You can utilize ``method()`` in order to know if you're reading
Andrey Andreev303eef02012-11-06 14:55:48 +0200109 PUT, DELETE or PATCH data.
110
Andrey Andreev04535c72014-01-06 10:57:05 +0200111***************
112Class Reference
113***************
Derek Jones8ede1a22011-10-05 13:34:52 -0500114
Andrey Andreev04535c72014-01-06 10:57:05 +0200115.. class:: CI_Input
Derek Jones8ede1a22011-10-05 13:34:52 -0500116
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200117 .. method:: post([$index = NULL[, $xss_clean = NULL]])
Derek Jones8ede1a22011-10-05 13:34:52 -0500118
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200119 :param mixed $index: POST parameter name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200120 :param bool $xss_clean: Whether to apply XSS filtering
121 :returns: $_POST if no parameters supplied, otherwise the POST value if found or NULL if not
122 :rtype: mixed
Derek Jones8ede1a22011-10-05 13:34:52 -0500123
Andrey Andreev04535c72014-01-06 10:57:05 +0200124 The first parameter will contain the name of the POST item you are
125 looking for::
Derek Jones8831d112011-10-05 15:57:02 -0500126
Andrey Andreev04535c72014-01-06 10:57:05 +0200127 $this->input->post('some_data');
Derek Jones8ede1a22011-10-05 13:34:52 -0500128
Andrey Andreev04535c72014-01-06 10:57:05 +0200129 The method returns NULL if the item you are attempting to retrieve
130 does not exist.
Derek Jones8ede1a22011-10-05 13:34:52 -0500131
Andrey Andreev04535c72014-01-06 10:57:05 +0200132 The second optional parameter lets you run the data through the XSS
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200133 filter. It's enabled by setting the second parameter to boolean TRUE
134 or by setting your ``$config['global_xss_filtering']`` to TRUE.
Andrey Andreev04535c72014-01-06 10:57:05 +0200135 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500136
Andrey Andreev04535c72014-01-06 10:57:05 +0200137 $this->input->post('some_data', TRUE);
Derek Jones8ede1a22011-10-05 13:34:52 -0500138
Andrey Andreev04535c72014-01-06 10:57:05 +0200139 To return an array of all POST items call without any parameters.
Derek Jones8ede1a22011-10-05 13:34:52 -0500140
Andrey Andreev04535c72014-01-06 10:57:05 +0200141 To return all POST items and pass them through the XSS filter set the
142 first parameter NULL while setting the second parameter to boolean TRUE.
143 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500144
Andrey Andreev04535c72014-01-06 10:57:05 +0200145 $this->input->post(NULL, TRUE); // returns all POST items with XSS filter
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200146 $this->input->post(NULL, FALSE); // returns all POST items without XSS filter
David Wosnitzad31a4e62014-12-12 16:35:35 +0100147
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200148 To return an array of multiple POST parameters, pass all the required keys
149 as an array.
150 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100151
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200152 $this->input->post(array('field1', 'field2'));
David Wosnitzad31a4e62014-12-12 16:35:35 +0100153
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200154 Same rule applied here, to retrive the parameters with XSS filtering enabled, set the
155 second parameter to boolean TRUE.
156 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100157
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200158 $this->input->post(array('field1', 'field2'), TRUE);
Derek Jones8ede1a22011-10-05 13:34:52 -0500159
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200160 .. method:: get([$index = NULL[, $xss_clean = NULL]])
Derek Jones8ede1a22011-10-05 13:34:52 -0500161
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200162 :param mixed $index: GET parameter name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200163 :param bool $xss_clean: Whether to apply XSS filtering
164 :returns: $_GET if no parameters supplied, otherwise the GET value if found or NULL if not
165 :rtype: mixed
Derek Jones8ede1a22011-10-05 13:34:52 -0500166
Andrey Andreev04535c72014-01-06 10:57:05 +0200167 This method is identical to ``post()``, only it fetches GET data.
168 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500169
Andrey Andreev04535c72014-01-06 10:57:05 +0200170 $this->input->get('some_data', TRUE);
171
172 To return an array of all GET items call without any parameters.
173
174 To return all GET items and pass them through the XSS filter set the
175 first parameter NULL while setting the second parameter to boolean TRUE.
176 ::
177
178 $this->input->get(NULL, TRUE); // returns all GET items with XSS filter
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200179 $this->input->get(NULL, FALSE); // returns all GET items without XSS filtering
David Wosnitzad31a4e62014-12-12 16:35:35 +0100180
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200181 To return an array of multiple GET parameters, pass all the required keys
182 as an array.
183 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100184
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200185 $this->input->get(array('field1', 'field2'));
David Wosnitzad31a4e62014-12-12 16:35:35 +0100186
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200187 Same rule applied here, to retrive the parameters with XSS filtering enabled, set the
188 second parameter to boolean TRUE.
189 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100190
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200191 $this->input->get(array('field1', 'field2'), TRUE);
Andrey Andreev04535c72014-01-06 10:57:05 +0200192
Andrey Andreev7c60b122014-02-08 18:47:19 +0200193 .. method:: post_get($index[, $xss_clean = NULL])
Andrey Andreevea801ab2014-01-20 15:03:43 +0200194
Andrey Andreev28c2c972014-02-08 04:27:48 +0200195 :param string $index: POST/GET parameter name
196 :param bool $xss_clean: Whether to apply XSS filtering
197 :returns: POST/GET value if found, NULL if not
198 :rtype: mixed
Andrey Andreevea801ab2014-01-20 15:03:43 +0200199
Andrey Andreev7c60b122014-02-08 18:47:19 +0200200 This method works pretty much the same way as ``post()`` and ``get()``,
201 only combined. It will search through both POST and GET streams for data,
202 looking in POST first, and then in GET::
Andrey Andreevea801ab2014-01-20 15:03:43 +0200203
204 $this->input->post_get('some_data', TRUE);
205
Andrey Andreev7c60b122014-02-08 18:47:19 +0200206 .. method:: get_post($index[, $xss_clean = NULL])
Andrey Andreev04535c72014-01-06 10:57:05 +0200207
Andrey Andreev28c2c972014-02-08 04:27:48 +0200208 :param string $index: GET/POST parameter name
209 :param bool $xss_clean: Whether to apply XSS filtering
210 :returns: GET/POST value if found, NULL if not
211 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200212
Andrey Andreevea801ab2014-01-20 15:03:43 +0200213 This method works the same way as ``post_get()`` only it looks for GET
214 data first.
Andrey Andreev04535c72014-01-06 10:57:05 +0200215
216 $this->input->get_post('some_data', TRUE);
217
Andrey Andreevea801ab2014-01-20 15:03:43 +0200218 .. note:: This method used to act EXACTLY like ``post_get()``, but it's
219 behavior has changed in CodeIgniter 3.0.
220
Andrey Andreev7c60b122014-02-08 18:47:19 +0200221 .. method:: cookie([$index = NULL[, $xss_clean = NULL]])
Andrey Andreev04535c72014-01-06 10:57:05 +0200222
Andrey Andreevef29f832014-12-02 18:03:47 +0200223 :param mixed $index: COOKIE name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200224 :param bool $xss_clean: Whether to apply XSS filtering
225 :returns: $_COOKIE if no parameters supplied, otherwise the COOKIE value if found or NULL if not
226 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200227
228 This method is identical to ``post()`` and ``get()``, only it fetches cookie
229 data::
230
231 $this->input->cookie('some_cookie');
232 $this->input->cookie('some_cookie, TRUE); // with XSS filter
David Wosnitzad31a4e62014-12-12 16:35:35 +0100233
Andrey Andreevef29f832014-12-02 18:03:47 +0200234 To return an array of multiple cookie values, pass all the required keys
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200235 as an array.
236 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100237
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200238 $this->input->cookie(array('some_cookie', 'some_cookie2'));
Andrey Andreev04535c72014-01-06 10:57:05 +0200239
Andrey Andreev7c60b122014-02-08 18:47:19 +0200240 .. method:: server($index[, $xss_clean = NULL])
Andrey Andreev04535c72014-01-06 10:57:05 +0200241
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200242 :param mixed $index: Value name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200243 :param bool $xss_clean: Whether to apply XSS filtering
244 :returns: $_SERVER item value if found, NULL if not
245 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200246
Andrey Andreev7c60b122014-02-08 18:47:19 +0200247 This method is identical to the ``post()``, ``get()`` and ``cookie()``
248 methods, only it fetches server data (``$_SERVER``)::
Andrey Andreev04535c72014-01-06 10:57:05 +0200249
250 $this->input->server('some_data');
251
Andrey Andreevef29f832014-12-02 18:03:47 +0200252 To return an array of multiple ``$_SERVER`` values, pass all the required keys
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200253 as an array.
254 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100255
256 $this->input->server(array('SERVER_PROTOCOL', 'REQUEST_URI'));
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200257
Andrey Andreev7c60b122014-02-08 18:47:19 +0200258 .. method:: input_stream([$index = NULL[, $xss_clean = NULL]])
Andrey Andreev04535c72014-01-06 10:57:05 +0200259
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200260 :param mixed $index: Key name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200261 :param bool $xss_clean: Whether to apply XSS filtering
262 :returns: Input stream array if no parameters supplied, otherwise the specified value if found or NULL if not
263 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200264
265 This method is identical to ``get()``, ``post()`` and ``cookie()``,
266 only it fetches the *php://input* stream data.
267
268 .. method:: set_cookie($name = ''[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = FALSE[, $httponly = FALSE]]]]]]])
269
Andrey Andreev28c2c972014-02-08 04:27:48 +0200270 :param mixed $name: Cookie name or an array of parameters
271 :param string $value: Cookie value
272 :param int $expire: Cookie expiration time in seconds
273 :param string $domain: Cookie domain
274 :param string $path: Cookie path
275 :param string $prefix: Cookie name prefix
276 :param bool $secure: Whether to only transfer the cookie through HTTPS
277 :param bool $httponly: Whether to only make the cookie accessible for HTTP requests (no JavaScript)
278 :rtype: void
279
Andrey Andreev04535c72014-01-06 10:57:05 +0200280
281 Sets a cookie containing the values you specify. There are two ways to
282 pass information to this method so that a cookie can be set: Array
283 Method, and Discrete Parameters:
284
Connor Tumbleson75b3fb22014-01-11 06:58:43 -0600285 **Array Method**
Andrey Andreev04535c72014-01-06 10:57:05 +0200286
287 Using this method, an associative array is passed to the first
288 parameter::
289
290 $cookie = array(
291 'name' => 'The Cookie Name',
292 'value' => 'The Value',
293 'expire' => '86500',
294 'domain' => '.some-domain.com',
295 'path' => '/',
296 'prefix' => 'myprefix_',
297 'secure' => TRUE
298 );
299
300 $this->input->set_cookie($cookie);
301
Andrey Andreev28c2c972014-02-08 04:27:48 +0200302 **Notes**
Andrey Andreev04535c72014-01-06 10:57:05 +0200303
304 Only the name and value are required. To delete a cookie set it with the
305 expiration blank.
306
307 The expiration is set in **seconds**, which will be added to the current
308 time. Do not include the time, but rather only the number of seconds
309 from *now* that you wish the cookie to be valid. If the expiration is
310 set to zero the cookie will only last as long as the browser is open.
311
312 For site-wide cookies regardless of how your site is requested, add your
313 URL to the **domain** starting with a period, like this:
314 .your-domain.com
315
316 The path is usually not needed since the method sets a root path.
317
318 The prefix is only needed if you need to avoid name collisions with
319 other identically named cookies for your server.
320
321 The secure boolean is only needed if you want to make it a secure cookie
322 by setting it to TRUE.
323
Connor Tumbleson75b3fb22014-01-11 06:58:43 -0600324 **Discrete Parameters**
Andrey Andreev04535c72014-01-06 10:57:05 +0200325
326 If you prefer, you can set the cookie by passing data using individual
327 parameters::
328
329 $this->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure);
Derek Jones8ede1a22011-10-05 13:34:52 -0500330
Andrey Andreev04535c72014-01-06 10:57:05 +0200331 .. method:: ip_address()
Derek Jones8ede1a22011-10-05 13:34:52 -0500332
Andrey Andreev28c2c972014-02-08 04:27:48 +0200333 :returns: Visitor's IP address or '0.0.0.0' if not valid
334 :rtype: string
Derek Jones8ede1a22011-10-05 13:34:52 -0500335
Andrey Andreev04535c72014-01-06 10:57:05 +0200336 Returns the IP address for the current user. If the IP address is not
337 valid, the method will return '0.0.0.0'::
Derek Jones8ede1a22011-10-05 13:34:52 -0500338
Andrey Andreev04535c72014-01-06 10:57:05 +0200339 echo $this->input->ip_address();
Derek Jones8ede1a22011-10-05 13:34:52 -0500340
Andrey Andreev04535c72014-01-06 10:57:05 +0200341 .. important:: This method takes into account the ``$config['proxy_ips']``
342 setting and will return the reported HTTP_X_FORWARDED_FOR,
343 HTTP_CLIENT_IP, HTTP_X_CLIENT_IP or HTTP_X_CLUSTER_CLIENT_IP
344 address for the allowed IP addresses.
Derek Jones8ede1a22011-10-05 13:34:52 -0500345
Andrey Andreev04535c72014-01-06 10:57:05 +0200346 .. method:: valid_ip($ip[, $which = ''])
Andrey Andreev303eef02012-11-06 14:55:48 +0200347
Andrey Andreev28c2c972014-02-08 04:27:48 +0200348 :param string $ip: IP address
349 :param string $which: IP protocol ('ipv4' or 'ipv6')
350 :returns: TRUE if the address is valid, FALSE if not
351 :rtype: bool
Derek Jones8ede1a22011-10-05 13:34:52 -0500352
Andrey Andreev04535c72014-01-06 10:57:05 +0200353 Takes an IP address as input and returns TRUE or FALSE (boolean) depending
354 on whether it is valid or not.
Derek Jones8ede1a22011-10-05 13:34:52 -0500355
Andrey Andreev04535c72014-01-06 10:57:05 +0200356 .. note:: The $this->input->ip_address() method above automatically
357 validates the IP address.
Derek Jones8ede1a22011-10-05 13:34:52 -0500358
Andrey Andreev04535c72014-01-06 10:57:05 +0200359 ::
Andrey Andreev5a257182012-06-10 06:18:14 +0300360
Andrey Andreev04535c72014-01-06 10:57:05 +0200361 if ( ! $this->input->valid_ip($ip))
362 {
363 echo 'Not Valid';
364 }
365 else
366 {
367 echo 'Valid';
368 }
Derek Jones8ede1a22011-10-05 13:34:52 -0500369
Andrey Andreev04535c72014-01-06 10:57:05 +0200370 Accepts an optional second string parameter of 'ipv4' or 'ipv6' to specify
371 an IP format. The default checks for both formats.
Derek Jones8ede1a22011-10-05 13:34:52 -0500372
Andrey Andreev8850e372014-02-27 21:56:06 +0200373 .. method:: user_agent([$xss_clean = NULL])
Derek Jones8ede1a22011-10-05 13:34:52 -0500374
Andrey Andreev28c2c972014-02-08 04:27:48 +0200375 :returns: User agent string or NULL if not set
Andrey Andreev8850e372014-02-27 21:56:06 +0200376 :param bool $xss_clean: Whether to apply XSS filtering
Andrey Andreev28c2c972014-02-08 04:27:48 +0200377 :rtype: mixed
Derek Jones8ede1a22011-10-05 13:34:52 -0500378
Andrey Andreev04535c72014-01-06 10:57:05 +0200379 Returns the user agent string (web browser) being used by the current user,
380 or NULL if it's not available.
381 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500382
Andrey Andreev04535c72014-01-06 10:57:05 +0200383 echo $this->input->user_agent();
Derek Jones8ede1a22011-10-05 13:34:52 -0500384
Andrey Andreev04535c72014-01-06 10:57:05 +0200385 See the :doc:`User Agent Class <user_agent>` for methods which extract
386 information from the user agent string.
Derek Jones8ede1a22011-10-05 13:34:52 -0500387
Andrey Andreev04535c72014-01-06 10:57:05 +0200388 .. method:: request_headers([$xss_clean = FALSE])
Derek Jones8ede1a22011-10-05 13:34:52 -0500389
Andrey Andreev28c2c972014-02-08 04:27:48 +0200390 :param bool $xss_clean: Whether to apply XSS filtering
391 :returns: An array of HTTP request headers
392 :rtype: array
Derek Jones8ede1a22011-10-05 13:34:52 -0500393
Andrey Andreev04535c72014-01-06 10:57:05 +0200394 Returns an array of HTTP request headers.
395 Useful if running in a non-Apache environment where
396 `apache_request_headers() <http://php.net/apache_request_headers>`_
397 will not be supported.
398 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500399
Andrey Andreev04535c72014-01-06 10:57:05 +0200400 $headers = $this->input->request_headers();
Derek Jones8ede1a22011-10-05 13:34:52 -0500401
Andrey Andreev04535c72014-01-06 10:57:05 +0200402 .. method:: get_request_header($index[, $xss_clean = FALSE])
Derek Jones8ede1a22011-10-05 13:34:52 -0500403
Andrey Andreev28c2c972014-02-08 04:27:48 +0200404 :param string $index: HTTP request header name
405 :param bool $xss_clean: Whether to apply XSS filtering
406 :returns: An HTTP request header or NULL if not found
407 :rtype: string
Derek Jones8ede1a22011-10-05 13:34:52 -0500408
Andrey Andreev04535c72014-01-06 10:57:05 +0200409 Returns a single member of the request headers array or NULL
410 if the searched header is not found.
411 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500412
Andrey Andreev04535c72014-01-06 10:57:05 +0200413 $this->input->get_request_header('some-header', TRUE);
Derek Jones8ede1a22011-10-05 13:34:52 -0500414
Andrey Andreev04535c72014-01-06 10:57:05 +0200415 .. method:: is_ajax_request()
Derek Jones8ede1a22011-10-05 13:34:52 -0500416
Andrey Andreev28c2c972014-02-08 04:27:48 +0200417 :returns: TRUE if it is an Ajax request, FALSE if not
418 :rtype: bool
Derek Jones8ede1a22011-10-05 13:34:52 -0500419
Andrey Andreev04535c72014-01-06 10:57:05 +0200420 Checks to see if the HTTP_X_REQUESTED_WITH server header has been
421 set, and returns boolean TRUE if it is or FALSE if not.
Derek Jones8ede1a22011-10-05 13:34:52 -0500422
Andrey Andreev04535c72014-01-06 10:57:05 +0200423 .. method:: is_cli_request()
Derek Jones8ede1a22011-10-05 13:34:52 -0500424
Andrey Andreev28c2c972014-02-08 04:27:48 +0200425 :returns: TRUE if it is a CLI request, FALSE if not
426 :rtype: bool
Michiel Vugteveenbe0ca262012-03-07 19:09:51 +0100427
Andrey Andreev04535c72014-01-06 10:57:05 +0200428 Checks to see if the application was run from the command-line
429 interface.
Michiel Vugteveenbe0ca262012-03-07 19:09:51 +0100430
Andrey Andreev04535c72014-01-06 10:57:05 +0200431 .. note:: This method checks both the PHP SAPI name currently in use
432 and if the ``STDIN`` constant is defined, which is usually a
433 failsafe way to see if PHP is being run via the command line.
Michiel Vugteveenbe0ca262012-03-07 19:09:51 +0100434
Andrey Andreev04535c72014-01-06 10:57:05 +0200435 ::
436
437 $this->input->is_cli_request()
438
Andrey Andreevea801ab2014-01-20 15:03:43 +0200439 .. note:: This method is DEPRECATED and is now just an alias for the
440 :func:`is_cli()` function.
441
Andrey Andreev04535c72014-01-06 10:57:05 +0200442 .. method:: method([$upper = FALSE])
443
Andrey Andreev28c2c972014-02-08 04:27:48 +0200444 :param bool $upper: Whether to return the request method name in upper or lower case
445 :returns: HTTP request method
446 :rtype: string
Andrey Andreev04535c72014-01-06 10:57:05 +0200447
448 Returns the ``$_SERVER['REQUEST_METHOD']``, with the option to set it
449 in uppercase or lowercase.
450 ::
451
452 echo $this->input->method(TRUE); // Outputs: POST
453 echo $this->input->method(FALSE); // Outputs: post
David Wosnitzad31a4e62014-12-12 16:35:35 +0100454 echo $this->input->method(); // Outputs: post