blob: 1123471295bf12864a138f26ac281e17f2a965d2 [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
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200139
140 To return an array of multiple POST parameters, pass all the required keys
141 as an array.
142 ::
143 $this->input->post(array('field1', 'field2'));
144
145 Same rule applied here, to retrive the parameters with XSS filtering enabled, set the
146 second parameter to boolean TRUE.
147 ::
148 $this->input->post(array('field1', 'field2'), TRUE);
Derek Jones8ede1a22011-10-05 13:34:52 -0500149
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200150 .. method:: get([$index = NULL[, $xss_clean = NULL]])
Derek Jones8ede1a22011-10-05 13:34:52 -0500151
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200152 :param mixed $index: GET parameter name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200153 :param bool $xss_clean: Whether to apply XSS filtering
154 :returns: $_GET if no parameters supplied, otherwise the GET value if found or NULL if not
155 :rtype: mixed
Derek Jones8ede1a22011-10-05 13:34:52 -0500156
Andrey Andreev04535c72014-01-06 10:57:05 +0200157 This method is identical to ``post()``, only it fetches GET data.
158 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500159
Andrey Andreev04535c72014-01-06 10:57:05 +0200160 $this->input->get('some_data', TRUE);
161
162 To return an array of all GET items call without any parameters.
163
164 To return all GET items and pass them through the XSS filter set the
165 first parameter NULL while setting the second parameter to boolean TRUE.
166 ::
167
168 $this->input->get(NULL, TRUE); // returns all GET items with XSS filter
Andrey Andreev88ebdf72014-01-08 17:28:02 +0200169 $this->input->get(NULL, FALSE); // returns all GET items without XSS filtering
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200170
171 To return an array of multiple GET parameters, pass all the required keys
172 as an array.
173 ::
174 $this->input->get(array('field1', 'field2'));
175
176 Same rule applied here, to retrive the parameters with XSS filtering enabled, set the
177 second parameter to boolean TRUE.
178 ::
179 $this->input->get(array('field1', 'field2'), TRUE);
Andrey Andreev04535c72014-01-06 10:57:05 +0200180
Andrey Andreev7c60b122014-02-08 18:47:19 +0200181 .. method:: post_get($index[, $xss_clean = NULL])
Andrey Andreevea801ab2014-01-20 15:03:43 +0200182
Andrey Andreev28c2c972014-02-08 04:27:48 +0200183 :param string $index: POST/GET parameter name
184 :param bool $xss_clean: Whether to apply XSS filtering
185 :returns: POST/GET value if found, NULL if not
186 :rtype: mixed
Andrey Andreevea801ab2014-01-20 15:03:43 +0200187
Andrey Andreev7c60b122014-02-08 18:47:19 +0200188 This method works pretty much the same way as ``post()`` and ``get()``,
189 only combined. It will search through both POST and GET streams for data,
190 looking in POST first, and then in GET::
Andrey Andreevea801ab2014-01-20 15:03:43 +0200191
192 $this->input->post_get('some_data', TRUE);
193
Andrey Andreev7c60b122014-02-08 18:47:19 +0200194 .. method:: get_post($index[, $xss_clean = NULL])
Andrey Andreev04535c72014-01-06 10:57:05 +0200195
Andrey Andreev28c2c972014-02-08 04:27:48 +0200196 :param string $index: GET/POST parameter name
197 :param bool $xss_clean: Whether to apply XSS filtering
198 :returns: GET/POST value if found, NULL if not
199 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200200
Andrey Andreevea801ab2014-01-20 15:03:43 +0200201 This method works the same way as ``post_get()`` only it looks for GET
202 data first.
Andrey Andreev04535c72014-01-06 10:57:05 +0200203
204 $this->input->get_post('some_data', TRUE);
205
Andrey Andreevea801ab2014-01-20 15:03:43 +0200206 .. note:: This method used to act EXACTLY like ``post_get()``, but it's
207 behavior has changed in CodeIgniter 3.0.
208
Andrey Andreev7c60b122014-02-08 18:47:19 +0200209 .. method:: cookie([$index = NULL[, $xss_clean = NULL]])
Andrey Andreev04535c72014-01-06 10:57:05 +0200210
Andrey Andreevef29f832014-12-02 18:03:47 +0200211 :param mixed $index: COOKIE name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200212 :param bool $xss_clean: Whether to apply XSS filtering
213 :returns: $_COOKIE if no parameters supplied, otherwise the COOKIE value if found or NULL if not
214 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200215
216 This method is identical to ``post()`` and ``get()``, only it fetches cookie
217 data::
218
219 $this->input->cookie('some_cookie');
220 $this->input->cookie('some_cookie, TRUE); // with XSS filter
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200221
Andrey Andreevef29f832014-12-02 18:03:47 +0200222 To return an array of multiple cookie values, pass all the required keys
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200223 as an array.
224 ::
225 $this->input->cookie(array('some_cookie', 'some_cookie2'));
Andrey Andreev04535c72014-01-06 10:57:05 +0200226
Andrey Andreev7c60b122014-02-08 18:47:19 +0200227 .. method:: server($index[, $xss_clean = NULL])
Andrey Andreev04535c72014-01-06 10:57:05 +0200228
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200229 :param mixed $index: Value name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200230 :param bool $xss_clean: Whether to apply XSS filtering
231 :returns: $_SERVER item value if found, NULL if not
232 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200233
Andrey Andreev7c60b122014-02-08 18:47:19 +0200234 This method is identical to the ``post()``, ``get()`` and ``cookie()``
235 methods, only it fetches server data (``$_SERVER``)::
Andrey Andreev04535c72014-01-06 10:57:05 +0200236
237 $this->input->server('some_data');
238
Andrey Andreevef29f832014-12-02 18:03:47 +0200239 To return an array of multiple ``$_SERVER`` values, pass all the required keys
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200240 as an array.
241 ::
242 $this->input->server(array('SERVER_PROTOCOL', 'REQUEST_URI'));
243
Andrey Andreev7c60b122014-02-08 18:47:19 +0200244 .. method:: input_stream([$index = NULL[, $xss_clean = NULL]])
Andrey Andreev04535c72014-01-06 10:57:05 +0200245
Ahmad Anbarff89a4e2014-12-02 17:26:30 +0200246 :param mixed $index: Key name
Andrey Andreev28c2c972014-02-08 04:27:48 +0200247 :param bool $xss_clean: Whether to apply XSS filtering
248 :returns: Input stream array if no parameters supplied, otherwise the specified value if found or NULL if not
249 :rtype: mixed
Andrey Andreev04535c72014-01-06 10:57:05 +0200250
251 This method is identical to ``get()``, ``post()`` and ``cookie()``,
252 only it fetches the *php://input* stream data.
253
254 .. method:: set_cookie($name = ''[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = FALSE[, $httponly = FALSE]]]]]]])
255
Andrey Andreev28c2c972014-02-08 04:27:48 +0200256 :param mixed $name: Cookie name or an array of parameters
257 :param string $value: Cookie value
258 :param int $expire: Cookie expiration time in seconds
259 :param string $domain: Cookie domain
260 :param string $path: Cookie path
261 :param string $prefix: Cookie name prefix
262 :param bool $secure: Whether to only transfer the cookie through HTTPS
263 :param bool $httponly: Whether to only make the cookie accessible for HTTP requests (no JavaScript)
264 :rtype: void
265
Andrey Andreev04535c72014-01-06 10:57:05 +0200266
267 Sets a cookie containing the values you specify. There are two ways to
268 pass information to this method so that a cookie can be set: Array
269 Method, and Discrete Parameters:
270
Connor Tumbleson75b3fb22014-01-11 06:58:43 -0600271 **Array Method**
Andrey Andreev04535c72014-01-06 10:57:05 +0200272
273 Using this method, an associative array is passed to the first
274 parameter::
275
276 $cookie = array(
277 'name' => 'The Cookie Name',
278 'value' => 'The Value',
279 'expire' => '86500',
280 'domain' => '.some-domain.com',
281 'path' => '/',
282 'prefix' => 'myprefix_',
283 'secure' => TRUE
284 );
285
286 $this->input->set_cookie($cookie);
287
Andrey Andreev28c2c972014-02-08 04:27:48 +0200288 **Notes**
Andrey Andreev04535c72014-01-06 10:57:05 +0200289
290 Only the name and value are required. To delete a cookie set it with the
291 expiration blank.
292
293 The expiration is set in **seconds**, which will be added to the current
294 time. Do not include the time, but rather only the number of seconds
295 from *now* that you wish the cookie to be valid. If the expiration is
296 set to zero the cookie will only last as long as the browser is open.
297
298 For site-wide cookies regardless of how your site is requested, add your
299 URL to the **domain** starting with a period, like this:
300 .your-domain.com
301
302 The path is usually not needed since the method sets a root path.
303
304 The prefix is only needed if you need to avoid name collisions with
305 other identically named cookies for your server.
306
307 The secure boolean is only needed if you want to make it a secure cookie
308 by setting it to TRUE.
309
Connor Tumbleson75b3fb22014-01-11 06:58:43 -0600310 **Discrete Parameters**
Andrey Andreev04535c72014-01-06 10:57:05 +0200311
312 If you prefer, you can set the cookie by passing data using individual
313 parameters::
314
315 $this->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure);
Derek Jones8ede1a22011-10-05 13:34:52 -0500316
Andrey Andreev04535c72014-01-06 10:57:05 +0200317 .. method:: ip_address()
Derek Jones8ede1a22011-10-05 13:34:52 -0500318
Andrey Andreev28c2c972014-02-08 04:27:48 +0200319 :returns: Visitor's IP address or '0.0.0.0' if not valid
320 :rtype: string
Derek Jones8ede1a22011-10-05 13:34:52 -0500321
Andrey Andreev04535c72014-01-06 10:57:05 +0200322 Returns the IP address for the current user. If the IP address is not
323 valid, the method will return '0.0.0.0'::
Derek Jones8ede1a22011-10-05 13:34:52 -0500324
Andrey Andreev04535c72014-01-06 10:57:05 +0200325 echo $this->input->ip_address();
Derek Jones8ede1a22011-10-05 13:34:52 -0500326
Andrey Andreev04535c72014-01-06 10:57:05 +0200327 .. important:: This method takes into account the ``$config['proxy_ips']``
328 setting and will return the reported HTTP_X_FORWARDED_FOR,
329 HTTP_CLIENT_IP, HTTP_X_CLIENT_IP or HTTP_X_CLUSTER_CLIENT_IP
330 address for the allowed IP addresses.
Derek Jones8ede1a22011-10-05 13:34:52 -0500331
Andrey Andreev04535c72014-01-06 10:57:05 +0200332 .. method:: valid_ip($ip[, $which = ''])
Andrey Andreev303eef02012-11-06 14:55:48 +0200333
Andrey Andreev28c2c972014-02-08 04:27:48 +0200334 :param string $ip: IP address
335 :param string $which: IP protocol ('ipv4' or 'ipv6')
336 :returns: TRUE if the address is valid, FALSE if not
337 :rtype: bool
Derek Jones8ede1a22011-10-05 13:34:52 -0500338
Andrey Andreev04535c72014-01-06 10:57:05 +0200339 Takes an IP address as input and returns TRUE or FALSE (boolean) depending
340 on whether it is valid or not.
Derek Jones8ede1a22011-10-05 13:34:52 -0500341
Andrey Andreev04535c72014-01-06 10:57:05 +0200342 .. note:: The $this->input->ip_address() method above automatically
343 validates the IP address.
Derek Jones8ede1a22011-10-05 13:34:52 -0500344
Andrey Andreev04535c72014-01-06 10:57:05 +0200345 ::
Andrey Andreev5a257182012-06-10 06:18:14 +0300346
Andrey Andreev04535c72014-01-06 10:57:05 +0200347 if ( ! $this->input->valid_ip($ip))
348 {
349 echo 'Not Valid';
350 }
351 else
352 {
353 echo 'Valid';
354 }
Derek Jones8ede1a22011-10-05 13:34:52 -0500355
Andrey Andreev04535c72014-01-06 10:57:05 +0200356 Accepts an optional second string parameter of 'ipv4' or 'ipv6' to specify
357 an IP format. The default checks for both formats.
Derek Jones8ede1a22011-10-05 13:34:52 -0500358
Andrey Andreev8850e372014-02-27 21:56:06 +0200359 .. method:: user_agent([$xss_clean = NULL])
Derek Jones8ede1a22011-10-05 13:34:52 -0500360
Andrey Andreev28c2c972014-02-08 04:27:48 +0200361 :returns: User agent string or NULL if not set
Andrey Andreev8850e372014-02-27 21:56:06 +0200362 :param bool $xss_clean: Whether to apply XSS filtering
Andrey Andreev28c2c972014-02-08 04:27:48 +0200363 :rtype: mixed
Derek Jones8ede1a22011-10-05 13:34:52 -0500364
Andrey Andreev04535c72014-01-06 10:57:05 +0200365 Returns the user agent string (web browser) being used by the current user,
366 or NULL if it's not available.
367 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500368
Andrey Andreev04535c72014-01-06 10:57:05 +0200369 echo $this->input->user_agent();
Derek Jones8ede1a22011-10-05 13:34:52 -0500370
Andrey Andreev04535c72014-01-06 10:57:05 +0200371 See the :doc:`User Agent Class <user_agent>` for methods which extract
372 information from the user agent string.
Derek Jones8ede1a22011-10-05 13:34:52 -0500373
Andrey Andreev04535c72014-01-06 10:57:05 +0200374 .. method:: request_headers([$xss_clean = FALSE])
Derek Jones8ede1a22011-10-05 13:34:52 -0500375
Andrey Andreev28c2c972014-02-08 04:27:48 +0200376 :param bool $xss_clean: Whether to apply XSS filtering
377 :returns: An array of HTTP request headers
378 :rtype: array
Derek Jones8ede1a22011-10-05 13:34:52 -0500379
Andrey Andreev04535c72014-01-06 10:57:05 +0200380 Returns an array of HTTP request headers.
381 Useful if running in a non-Apache environment where
382 `apache_request_headers() <http://php.net/apache_request_headers>`_
383 will not be supported.
384 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500385
Andrey Andreev04535c72014-01-06 10:57:05 +0200386 $headers = $this->input->request_headers();
Derek Jones8ede1a22011-10-05 13:34:52 -0500387
Andrey Andreev04535c72014-01-06 10:57:05 +0200388 .. method:: get_request_header($index[, $xss_clean = FALSE])
Derek Jones8ede1a22011-10-05 13:34:52 -0500389
Andrey Andreev28c2c972014-02-08 04:27:48 +0200390 :param string $index: HTTP request header name
391 :param bool $xss_clean: Whether to apply XSS filtering
392 :returns: An HTTP request header or NULL if not found
393 :rtype: string
Derek Jones8ede1a22011-10-05 13:34:52 -0500394
Andrey Andreev04535c72014-01-06 10:57:05 +0200395 Returns a single member of the request headers array or NULL
396 if the searched header is not found.
397 ::
Derek Jones8ede1a22011-10-05 13:34:52 -0500398
Andrey Andreev04535c72014-01-06 10:57:05 +0200399 $this->input->get_request_header('some-header', TRUE);
Derek Jones8ede1a22011-10-05 13:34:52 -0500400
Andrey Andreev04535c72014-01-06 10:57:05 +0200401 .. method:: is_ajax_request()
Derek Jones8ede1a22011-10-05 13:34:52 -0500402
Andrey Andreev28c2c972014-02-08 04:27:48 +0200403 :returns: TRUE if it is an Ajax request, FALSE if not
404 :rtype: bool
Derek Jones8ede1a22011-10-05 13:34:52 -0500405
Andrey Andreev04535c72014-01-06 10:57:05 +0200406 Checks to see if the HTTP_X_REQUESTED_WITH server header has been
407 set, and returns boolean TRUE if it is or FALSE if not.
Derek Jones8ede1a22011-10-05 13:34:52 -0500408
Andrey Andreev04535c72014-01-06 10:57:05 +0200409 .. method:: is_cli_request()
Derek Jones8ede1a22011-10-05 13:34:52 -0500410
Andrey Andreev28c2c972014-02-08 04:27:48 +0200411 :returns: TRUE if it is a CLI request, FALSE if not
412 :rtype: bool
Michiel Vugteveenbe0ca262012-03-07 19:09:51 +0100413
Andrey Andreev04535c72014-01-06 10:57:05 +0200414 Checks to see if the application was run from the command-line
415 interface.
Michiel Vugteveenbe0ca262012-03-07 19:09:51 +0100416
Andrey Andreev04535c72014-01-06 10:57:05 +0200417 .. note:: This method checks both the PHP SAPI name currently in use
418 and if the ``STDIN`` constant is defined, which is usually a
419 failsafe way to see if PHP is being run via the command line.
Michiel Vugteveenbe0ca262012-03-07 19:09:51 +0100420
Andrey Andreev04535c72014-01-06 10:57:05 +0200421 ::
422
423 $this->input->is_cli_request()
424
Andrey Andreevea801ab2014-01-20 15:03:43 +0200425 .. note:: This method is DEPRECATED and is now just an alias for the
426 :func:`is_cli()` function.
427
Andrey Andreev04535c72014-01-06 10:57:05 +0200428 .. method:: method([$upper = FALSE])
429
Andrey Andreev28c2c972014-02-08 04:27:48 +0200430 :param bool $upper: Whether to return the request method name in upper or lower case
431 :returns: HTTP request method
432 :rtype: string
Andrey Andreev04535c72014-01-06 10:57:05 +0200433
434 Returns the ``$_SERVER['REQUEST_METHOD']``, with the option to set it
435 in uppercase or lowercase.
436 ::
437
438 echo $this->input->method(TRUE); // Outputs: POST
439 echo $this->input->method(FALSE); // Outputs: post
440 echo $this->input->method(); // Outputs: post