blob: 300f4711209c697fe74599fd4deafbfce017f8e2 [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
Andrey Andreev9187ed32015-02-28 19:54:17 +020056.. important:: The 'global_xss_filtering' setting is DEPRECATED and kept
57 solely for backwards-compatibility purposes. XSS escaping should
58 be performed on *output*, not *input*!
59
James L Parry08191be2014-12-20 02:37:13 -080060*******************
61Accessing form data
62*******************
63
Andrey Andreev9cf12d12012-06-13 10:19:59 +030064Using POST, GET, COOKIE, or SERVER Data
65=======================================
Derek Jones8ede1a22011-10-05 13:34:52 -050066
Andrey Andreev04535c72014-01-06 10:57:05 +020067CodeIgniter comes with helper methods that let you fetch POST, GET,
Derek Jones8ede1a22011-10-05 13:34:52 -050068COOKIE or SERVER items. The main advantage of using the provided
Andrey Andreev303eef02012-11-06 14:55:48 +020069methods rather than fetching an item directly (``$_POST['something']``)
Andrey Andreev9cf12d12012-06-13 10:19:59 +030070is that the methods will check to see if the item is set and return
71NULL if not. This lets you conveniently use data without
Derek Jones8ede1a22011-10-05 13:34:52 -050072having to test whether an item exists first. In other words, normally
73you might do something like this::
74
Phil Sturgeon55a6ddb2012-05-23 18:37:24 +010075 $something = isset($_POST['something']) ? $_POST['something'] : NULL;
Derek Jones8ede1a22011-10-05 13:34:52 -050076
Andrey Andreev303eef02012-11-06 14:55:48 +020077With CodeIgniter's built in methods you can simply do this::
Derek Jones8ede1a22011-10-05 13:34:52 -050078
79 $something = $this->input->post('something');
80
Andrey Andreev04535c72014-01-06 10:57:05 +020081The main methods are:
Derek Jones8ede1a22011-10-05 13:34:52 -050082
Andrey Andreev28c2c972014-02-08 04:27:48 +020083- ``$this->input->post()``
84- ``$this->input->get()``
85- ``$this->input->cookie()``
86- ``$this->input->server()``
Derek Jones8ede1a22011-10-05 13:34:52 -050087
Andrey Andreev303eef02012-11-06 14:55:48 +020088Using the php://input stream
89============================
90
91If you want to utilize the PUT, DELETE, PATCH or other exotic request
92methods, they can only be accessed via a special input stream, that
93can only be read once. This isn't as easy as just reading from e.g.
94the ``$_POST`` array, because it will always exist and you can try
95and access multiple variables without caring that you might only have
96one shot at all of the POST data.
97
Ignasimg0b5569f2015-02-20 17:56:55 +010098CodeIgniter will take care of that for you, and you can read the data
99from the **php://input** stream at any time, just by using the
Ignasimg54b42d62015-02-26 03:16:12 +0100100``$raw_input_stream`` property::
Ignasimg0b5569f2015-02-20 17:56:55 +0100101
102 $this->input->raw_input_stream;
103
Ignasimg54b42d62015-02-26 03:16:12 +0100104Additionally if the input stream is form-encoded like $_POST you can
105access its values by calling the
Andrey Andreev303eef02012-11-06 14:55:48 +0200106``input_stream()`` method::
107
108 $this->input->input_stream('key');
109
Andrey Andreev04535c72014-01-06 10:57:05 +0200110Similar to other methods such as ``get()`` and ``post()``, if the
111requested data is not found, it will return NULL and you can also
112decide whether to run the data through ``xss_clean()`` by passing
113a boolean value as the second parameter::
Andrey Andreev303eef02012-11-06 14:55:48 +0200114
115 $this->input->input_stream('key', TRUE); // XSS Clean
116 $this->input->input_stream('key', FALSE); // No XSS filter
117
Andrey Andreev04535c72014-01-06 10:57:05 +0200118.. note:: You can utilize ``method()`` in order to know if you're reading
Andrey Andreev303eef02012-11-06 14:55:48 +0200119 PUT, DELETE or PATCH data.
120
Andrey Andreev04535c72014-01-06 10:57:05 +0200121***************
122Class Reference
123***************
Derek Jones8ede1a22011-10-05 13:34:52 -0500124
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200125.. php:class:: CI_Input
Derek Jones8ede1a22011-10-05 13:34:52 -0500126
Ignasimg54b42d62015-02-26 03:16:12 +0100127 .. attribute:: $raw_input_stream
128
129 Read only property that will return php://input data as is.
130
131 The property can be read multiple times.
132
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200133 .. php:method:: post([$index = NULL[, $xss_clean = NULL]])
Derek Jones8ede1a22011-10-05 13:34:52 -0500134
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200135 :param mixed $index: POST parameter name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200136 :param bool $xss_clean: Whether to apply XSS filtering
137 :returns: $_POST if no parameters supplied, otherwise the POST value if found or NULL if not
138 :rtype: mixed
Derek Jones8ede1a22011-10-05 13:34:52 -0500139
Andrey Andreev04535c72014-01-06 10:57:05 +0200140 The first parameter will contain the name of the POST item you are
141 looking for::
Derek Jones8831d112011-10-05 15:57:02 -0500142
Andrey Andreev04535c72014-01-06 10:57:05 +0200143 $this->input->post('some_data');
Derek Jones8ede1a22011-10-05 13:34:52 -0500144
Andrey Andreev04535c72014-01-06 10:57:05 +0200145 The method returns NULL if the item you are attempting to retrieve
146 does not exist.
Derek Jones8ede1a22011-10-05 13:34:52 -0500147
Andrey Andreev04535c72014-01-06 10:57:05 +0200148 The second optional parameter lets you run the data through the XSS
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200149 filter. It's enabled by setting the second parameter to boolean TRUE
150 or by setting your ``$config['global_xss_filtering']`` to TRUE.
Andrey Andreev04535c72014-01-06 10:57:05 +0200151 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500152
Andrey Andreev04535c72014-01-06 10:57:05 +0200153 $this->input->post('some_data', TRUE);
Derek Jones8ede1a22011-10-05 13:34:52 -0500154
Andrey Andreev04535c72014-01-06 10:57:05 +0200155 To return an array of all POST items call without any parameters.
Derek Jones8ede1a22011-10-05 13:34:52 -0500156
Andrey Andreev04535c72014-01-06 10:57:05 +0200157 To return all POST items and pass them through the XSS filter set the
158 first parameter NULL while setting the second parameter to boolean TRUE.
159 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500160
Andrey Andreev04535c72014-01-06 10:57:05 +0200161 $this->input->post(NULL, TRUE); // returns all POST items with XSS filter
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200162 $this->input->post(NULL, FALSE); // returns all POST items without XSS filter
David Wosnitzad31a4e62014-12-12 16:35:35 +0100163
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200164 To return an array of multiple POST parameters, pass all the required keys
165 as an array.
166 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100167
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200168 $this->input->post(array('field1', 'field2'));
David Wosnitzad31a4e62014-12-12 16:35:35 +0100169
Andrey Andreev71d8f722017-01-17 12:01:00 +0200170 Same rule applied here, to retrieve the parameters with XSS filtering enabled, set the
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200171 second parameter to boolean TRUE.
172 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100173
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200174 $this->input->post(array('field1', 'field2'), TRUE);
Derek Jones8ede1a22011-10-05 13:34:52 -0500175
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200176 .. php:method:: get([$index = NULL[, $xss_clean = NULL]])
Derek Jones8ede1a22011-10-05 13:34:52 -0500177
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200178 :param mixed $index: GET parameter name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200179 :param bool $xss_clean: Whether to apply XSS filtering
180 :returns: $_GET if no parameters supplied, otherwise the GET value if found or NULL if not
181 :rtype: mixed
Derek Jones8ede1a22011-10-05 13:34:52 -0500182
Andrey Andreev04535c72014-01-06 10:57:05 +0200183 This method is identical to ``post()``, only it fetches GET data.
184 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500185
Andrey Andreev04535c72014-01-06 10:57:05 +0200186 $this->input->get('some_data', TRUE);
187
188 To return an array of all GET items call without any parameters.
189
190 To return all GET items and pass them through the XSS filter set the
191 first parameter NULL while setting the second parameter to boolean TRUE.
192 ::
193
194 $this->input->get(NULL, TRUE); // returns all GET items with XSS filter
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200195 $this->input->get(NULL, FALSE); // returns all GET items without XSS filtering
David Wosnitzad31a4e62014-12-12 16:35:35 +0100196
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200197 To return an array of multiple GET parameters, pass all the required keys
198 as an array.
199 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100200
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200201 $this->input->get(array('field1', 'field2'));
David Wosnitzad31a4e62014-12-12 16:35:35 +0100202
Andrey Andreev71d8f722017-01-17 12:01:00 +0200203 Same rule applied here, to retrieve the parameters with XSS filtering enabled, set the
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200204 second parameter to boolean TRUE.
205 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100206
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200207 $this->input->get(array('field1', 'field2'), TRUE);
Andrey Andreev04535c72014-01-06 10:57:05 +0200208
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200209 .. php:method:: post_get($index[, $xss_clean = NULL])
Andrey Andreevea801ab2014-01-20 15:03:43 +0200210
Andrey Andreev28c2c972014-02-08 04:27:48 +0200211 :param string $index: POST/GET parameter name
212 :param bool $xss_clean: Whether to apply XSS filtering
213 :returns: POST/GET value if found, NULL if not
214 :rtype: mixed
Andrey Andreevea801ab2014-01-20 15:03:43 +0200215
Andrey Andreev7c60b122014-02-08 18:47:19 +0200216 This method works pretty much the same way as ``post()`` and ``get()``,
217 only combined. It will search through both POST and GET streams for data,
218 looking in POST first, and then in GET::
Andrey Andreevea801ab2014-01-20 15:03:43 +0200219
220 $this->input->post_get('some_data', TRUE);
221
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200222 .. php:method:: get_post($index[, $xss_clean = NULL])
Andrey Andreev04535c72014-01-06 10:57:05 +0200223
Andrey Andreev28c2c972014-02-08 04:27:48 +0200224 :param string $index: GET/POST parameter name
225 :param bool $xss_clean: Whether to apply XSS filtering
226 :returns: GET/POST value if found, NULL if not
227 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200228
Andrey Andreevea801ab2014-01-20 15:03:43 +0200229 This method works the same way as ``post_get()`` only it looks for GET
230 data first.
Andrey Andreev04535c72014-01-06 10:57:05 +0200231
232 $this->input->get_post('some_data', TRUE);
233
Andrey Andreevea801ab2014-01-20 15:03:43 +0200234 .. note:: This method used to act EXACTLY like ``post_get()``, but it's
235 behavior has changed in CodeIgniter 3.0.
236
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200237 .. php:method:: cookie([$index = NULL[, $xss_clean = NULL]])
Andrey Andreev04535c72014-01-06 10:57:05 +0200238
Andrey Andreevef29f832014-12-02 18:03:47 +0200239 :param mixed $index: COOKIE name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200240 :param bool $xss_clean: Whether to apply XSS filtering
241 :returns: $_COOKIE if no parameters supplied, otherwise the COOKIE value if found or NULL if not
242 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200243
244 This method is identical to ``post()`` and ``get()``, only it fetches cookie
245 data::
246
247 $this->input->cookie('some_cookie');
Andrey Andreev954c4aa2017-07-21 11:51:37 +0300248 $this->input->cookie('some_cookie', TRUE); // with XSS filter
David Wosnitzad31a4e62014-12-12 16:35:35 +0100249
Andrey Andreevef29f832014-12-02 18:03:47 +0200250 To return an array of multiple cookie values, pass all the required keys
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200251 as an array.
252 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100253
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200254 $this->input->cookie(array('some_cookie', 'some_cookie2'));
Andrey Andreev04535c72014-01-06 10:57:05 +0200255
Andrey Andreevb4834cc2015-01-29 13:52:44 +0200256 .. note:: Unlike the :doc:`Cookie Helper <../helpers/cookie_helper>`
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200257 function :php:func:`get_cookie()`, this method does NOT prepend
Andrey Andreevb4834cc2015-01-29 13:52:44 +0200258 your configured ``$config['cookie_prefix']`` value.
259
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200260 .. php:method:: server($index[, $xss_clean = NULL])
Andrey Andreev04535c72014-01-06 10:57:05 +0200261
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200262 :param mixed $index: Value name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200263 :param bool $xss_clean: Whether to apply XSS filtering
264 :returns: $_SERVER item value if found, NULL if not
265 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200266
Andrey Andreev7c60b122014-02-08 18:47:19 +0200267 This method is identical to the ``post()``, ``get()`` and ``cookie()``
268 methods, only it fetches server data (``$_SERVER``)::
Andrey Andreev04535c72014-01-06 10:57:05 +0200269
270 $this->input->server('some_data');
271
Andrey Andreevef29f832014-12-02 18:03:47 +0200272 To return an array of multiple ``$_SERVER`` values, pass all the required keys
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200273 as an array.
274 ::
David Wosnitzad31a4e62014-12-12 16:35:35 +0100275
276 $this->input->server(array('SERVER_PROTOCOL', 'REQUEST_URI'));
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200277
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200278 .. php:method:: input_stream([$index = NULL[, $xss_clean = NULL]])
Andrey Andreev04535c72014-01-06 10:57:05 +0200279
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200280 :param mixed $index: Key name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200281 :param bool $xss_clean: Whether to apply XSS filtering
282 :returns: Input stream array if no parameters supplied, otherwise the specified value if found or NULL if not
283 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200284
285 This method is identical to ``get()``, ``post()`` and ``cookie()``,
286 only it fetches the *php://input* stream data.
287
Andrey Andreev422b8892017-02-01 14:36:49 +0200288 .. php:method:: set_cookie($name = ''[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = NULL[, $httponly = NULL]]]]]]])
Andrey Andreev04535c72014-01-06 10:57:05 +0200289
Andrey Andreev28c2c972014-02-08 04:27:48 +0200290 :param mixed $name: Cookie name or an array of parameters
291 :param string $value: Cookie value
292 :param int $expire: Cookie expiration time in seconds
293 :param string $domain: Cookie domain
294 :param string $path: Cookie path
295 :param string $prefix: Cookie name prefix
296 :param bool $secure: Whether to only transfer the cookie through HTTPS
297 :param bool $httponly: Whether to only make the cookie accessible for HTTP requests (no JavaScript)
298 :rtype: void
299
Andrey Andreev04535c72014-01-06 10:57:05 +0200300
301 Sets a cookie containing the values you specify. There are two ways to
302 pass information to this method so that a cookie can be set: Array
303 Method, and Discrete Parameters:
304
Connor Tumbleson75b3fb22014-01-11 06:58:43 -0600305 **Array Method**
Andrey Andreev04535c72014-01-06 10:57:05 +0200306
307 Using this method, an associative array is passed to the first
308 parameter::
309
310 $cookie = array(
311 'name' => 'The Cookie Name',
312 'value' => 'The Value',
313 'expire' => '86500',
314 'domain' => '.some-domain.com',
315 'path' => '/',
316 'prefix' => 'myprefix_',
317 'secure' => TRUE
318 );
319
320 $this->input->set_cookie($cookie);
321
Andrey Andreev28c2c972014-02-08 04:27:48 +0200322 **Notes**
Andrey Andreev04535c72014-01-06 10:57:05 +0200323
324 Only the name and value are required. To delete a cookie set it with the
325 expiration blank.
326
327 The expiration is set in **seconds**, which will be added to the current
328 time. Do not include the time, but rather only the number of seconds
329 from *now* that you wish the cookie to be valid. If the expiration is
330 set to zero the cookie will only last as long as the browser is open.
331
332 For site-wide cookies regardless of how your site is requested, add your
333 URL to the **domain** starting with a period, like this:
334 .your-domain.com
335
336 The path is usually not needed since the method sets a root path.
337
338 The prefix is only needed if you need to avoid name collisions with
339 other identically named cookies for your server.
340
Andrey Andreev422b8892017-02-01 14:36:49 +0200341 The *httponly* and *secure* flags, when omitted, will default to your
342 ``$config['cookie_httponly']`` and ``$config['cookie_secure']`` settings.
Andrey Andreev04535c72014-01-06 10:57:05 +0200343
Connor Tumbleson75b3fb22014-01-11 06:58:43 -0600344 **Discrete Parameters**
Andrey Andreev04535c72014-01-06 10:57:05 +0200345
346 If you prefer, you can set the cookie by passing data using individual
347 parameters::
348
349 $this->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure);
Derek Jones8ede1a22011-10-05 13:34:52 -0500350
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200351 .. php:method:: ip_address()
Derek Jones8ede1a22011-10-05 13:34:52 -0500352
Andrey Andreev28c2c972014-02-08 04:27:48 +0200353 :returns: Visitor's IP address or '0.0.0.0' if not valid
354 :rtype: string
Derek Jones8ede1a22011-10-05 13:34:52 -0500355
Andrey Andreev04535c72014-01-06 10:57:05 +0200356 Returns the IP address for the current user. If the IP address is not
357 valid, the method will return '0.0.0.0'::
Derek Jones8ede1a22011-10-05 13:34:52 -0500358
Andrey Andreev04535c72014-01-06 10:57:05 +0200359 echo $this->input->ip_address();
Derek Jones8ede1a22011-10-05 13:34:52 -0500360
Andrey Andreev04535c72014-01-06 10:57:05 +0200361 .. important:: This method takes into account the ``$config['proxy_ips']``
362 setting and will return the reported HTTP_X_FORWARDED_FOR,
363 HTTP_CLIENT_IP, HTTP_X_CLIENT_IP or HTTP_X_CLUSTER_CLIENT_IP
364 address for the allowed IP addresses.
Derek Jones8ede1a22011-10-05 13:34:52 -0500365
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200366 .. php:method:: valid_ip($ip[, $which = ''])
Andrey Andreev303eef02012-11-06 14:55:48 +0200367
Andrey Andreev28c2c972014-02-08 04:27:48 +0200368 :param string $ip: IP address
369 :param string $which: IP protocol ('ipv4' or 'ipv6')
370 :returns: TRUE if the address is valid, FALSE if not
371 :rtype: bool
Derek Jones8ede1a22011-10-05 13:34:52 -0500372
Andrey Andreev04535c72014-01-06 10:57:05 +0200373 Takes an IP address as input and returns TRUE or FALSE (boolean) depending
374 on whether it is valid or not.
Derek Jones8ede1a22011-10-05 13:34:52 -0500375
Andrey Andreev04535c72014-01-06 10:57:05 +0200376 .. note:: The $this->input->ip_address() method above automatically
377 validates the IP address.
Derek Jones8ede1a22011-10-05 13:34:52 -0500378
Andrey Andreev04535c72014-01-06 10:57:05 +0200379 ::
Andrey Andreev5a257182012-06-10 06:18:14 +0300380
Andrey Andreev04535c72014-01-06 10:57:05 +0200381 if ( ! $this->input->valid_ip($ip))
382 {
383 echo 'Not Valid';
384 }
385 else
386 {
387 echo 'Valid';
388 }
Derek Jones8ede1a22011-10-05 13:34:52 -0500389
Andrey Andreev04535c72014-01-06 10:57:05 +0200390 Accepts an optional second string parameter of 'ipv4' or 'ipv6' to specify
391 an IP format. The default checks for both formats.
Derek Jones8ede1a22011-10-05 13:34:52 -0500392
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200393 .. php:method:: user_agent([$xss_clean = NULL])
Derek Jones8ede1a22011-10-05 13:34:52 -0500394
Andrey Andreev28c2c972014-02-08 04:27:48 +0200395 :returns: User agent string or NULL if not set
Andrey Andreev8850e372014-02-27 21:56:06 +0200396 :param bool $xss_clean: Whether to apply XSS filtering
Andrey Andreev28c2c972014-02-08 04:27:48 +0200397 :rtype: mixed
Derek Jones8ede1a22011-10-05 13:34:52 -0500398
Andrey Andreev04535c72014-01-06 10:57:05 +0200399 Returns the user agent string (web browser) being used by the current user,
400 or NULL if it's not available.
401 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500402
Andrey Andreev04535c72014-01-06 10:57:05 +0200403 echo $this->input->user_agent();
Derek Jones8ede1a22011-10-05 13:34:52 -0500404
Andrey Andreev04535c72014-01-06 10:57:05 +0200405 See the :doc:`User Agent Class <user_agent>` for methods which extract
406 information from the user agent string.
Derek Jones8ede1a22011-10-05 13:34:52 -0500407
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200408 .. php:method:: request_headers([$xss_clean = FALSE])
Derek Jones8ede1a22011-10-05 13:34:52 -0500409
Andrey Andreev28c2c972014-02-08 04:27:48 +0200410 :param bool $xss_clean: Whether to apply XSS filtering
411 :returns: An array of HTTP request headers
412 :rtype: array
Derek Jones8ede1a22011-10-05 13:34:52 -0500413
Andrey Andreev04535c72014-01-06 10:57:05 +0200414 Returns an array of HTTP request headers.
415 Useful if running in a non-Apache environment where
416 `apache_request_headers() <http://php.net/apache_request_headers>`_
417 will not be supported.
418 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500419
Andrey Andreev04535c72014-01-06 10:57:05 +0200420 $headers = $this->input->request_headers();
Derek Jones8ede1a22011-10-05 13:34:52 -0500421
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200422 .. php:method:: get_request_header($index[, $xss_clean = FALSE])
Derek Jones8ede1a22011-10-05 13:34:52 -0500423
Andrey Andreev28c2c972014-02-08 04:27:48 +0200424 :param string $index: HTTP request header name
425 :param bool $xss_clean: Whether to apply XSS filtering
426 :returns: An HTTP request header or NULL if not found
427 :rtype: string
Derek Jones8ede1a22011-10-05 13:34:52 -0500428
Andrey Andreev04535c72014-01-06 10:57:05 +0200429 Returns a single member of the request headers array or NULL
430 if the searched header is not found.
431 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500432
Andrey Andreev04535c72014-01-06 10:57:05 +0200433 $this->input->get_request_header('some-header', TRUE);
Derek Jones8ede1a22011-10-05 13:34:52 -0500434
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200435 .. php:method:: is_ajax_request()
Derek Jones8ede1a22011-10-05 13:34:52 -0500436
Andrey Andreev28c2c972014-02-08 04:27:48 +0200437 :returns: TRUE if it is an Ajax request, FALSE if not
438 :rtype: bool
Derek Jones8ede1a22011-10-05 13:34:52 -0500439
Andrey Andreev04535c72014-01-06 10:57:05 +0200440 Checks to see if the HTTP_X_REQUESTED_WITH server header has been
441 set, and returns boolean TRUE if it is or FALSE if not.
Derek Jones8ede1a22011-10-05 13:34:52 -0500442
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200443 .. php:method:: is_cli_request()
Derek Jones8ede1a22011-10-05 13:34:52 -0500444
Andrey Andreev28c2c972014-02-08 04:27:48 +0200445 :returns: TRUE if it is a CLI request, FALSE if not
446 :rtype: bool
Michiel Vugteveenbe0ca262012-03-07 19:09:51 +0100447
Andrey Andreev04535c72014-01-06 10:57:05 +0200448 Checks to see if the application was run from the command-line
449 interface.
Michiel Vugteveenbe0ca262012-03-07 19:09:51 +0100450
Andrey Andreev04535c72014-01-06 10:57:05 +0200451 .. note:: This method checks both the PHP SAPI name currently in use
452 and if the ``STDIN`` constant is defined, which is usually a
453 failsafe way to see if PHP is being run via the command line.
Michiel Vugteveenbe0ca262012-03-07 19:09:51 +0100454
Andrey Andreev04535c72014-01-06 10:57:05 +0200455 ::
456
457 $this->input->is_cli_request()
458
Andrey Andreevea801ab2014-01-20 15:03:43 +0200459 .. note:: This method is DEPRECATED and is now just an alias for the
460 :func:`is_cli()` function.
461
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200462 .. php:method:: method([$upper = FALSE])
Andrey Andreev04535c72014-01-06 10:57:05 +0200463
Andrey Andreev28c2c972014-02-08 04:27:48 +0200464 :param bool $upper: Whether to return the request method name in upper or lower case
465 :returns: HTTP request method
466 :rtype: string
Andrey Andreev04535c72014-01-06 10:57:05 +0200467
468 Returns the ``$_SERVER['REQUEST_METHOD']``, with the option to set it
469 in uppercase or lowercase.
470 ::
471
472 echo $this->input->method(TRUE); // Outputs: POST
473 echo $this->input->method(FALSE); // Outputs: post
David Wosnitzad31a4e62014-12-12 16:35:35 +0100474 echo $this->input->method(); // Outputs: post