Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ########### |
| 2 | Input Class |
| 3 | ########### |
| 4 | |
| 5 | The Input Class serves two purposes: |
| 6 | |
| 7 | #. It pre-processes global input data for security. |
Andrey Andreev | 303eef0 | 2012-11-06 14:55:48 +0200 | [diff] [blame] | 8 | #. It provides some helper methods for fetching input data and pre-processing it. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 9 | |
| 10 | .. note:: This class is initialized automatically by the system so there |
| 11 | is no need to do it manually. |
| 12 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 13 | .. contents:: |
| 14 | :local: |
| 15 | |
| 16 | .. raw:: html |
| 17 | |
| 18 | <div class="custom-index container"></div> |
| 19 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 20 | Security Filtering |
| 21 | ================== |
| 22 | |
Andrey Andreev | 303eef0 | 2012-11-06 14:55:48 +0200 | [diff] [blame] | 23 | The security filtering method is called automatically when a new |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 24 | :doc:`controller <../general/controllers>` is invoked. It does the |
| 25 | following: |
| 26 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 27 | - If ``$config['allow_get_array']`` is FALSE (default is TRUE), destroys |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 28 | 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. |
| 35 | - Standardizes newline characters to \\n(In Windows \\r\\n) |
| 36 | |
| 37 | XSS Filtering |
| 38 | ============= |
| 39 | |
| 40 | The Input class has the ability to filter input automatically to prevent |
| 41 | cross-site scripting attacks. If you want the filter to run |
| 42 | automatically every time it encounters POST or COOKIE data you can |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 43 | enable it by opening your *application/config/config.php* file and setting |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 44 | this:: |
| 45 | |
| 46 | $config['global_xss_filtering'] = TRUE; |
| 47 | |
| 48 | Please refer to the :doc:`Security class <security>` documentation for |
| 49 | information on using XSS Filtering in your application. |
| 50 | |
Andrey Andreev | 9cf12d1 | 2012-06-13 10:19:59 +0300 | [diff] [blame] | 51 | Using POST, GET, COOKIE, or SERVER Data |
| 52 | ======================================= |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 53 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 54 | CodeIgniter comes with helper methods that let you fetch POST, GET, |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 55 | COOKIE or SERVER items. The main advantage of using the provided |
Andrey Andreev | 303eef0 | 2012-11-06 14:55:48 +0200 | [diff] [blame] | 56 | methods rather than fetching an item directly (``$_POST['something']``) |
Andrey Andreev | 9cf12d1 | 2012-06-13 10:19:59 +0300 | [diff] [blame] | 57 | is that the methods will check to see if the item is set and return |
| 58 | NULL if not. This lets you conveniently use data without |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 59 | having to test whether an item exists first. In other words, normally |
| 60 | you might do something like this:: |
| 61 | |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 62 | $something = isset($_POST['something']) ? $_POST['something'] : NULL; |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 63 | |
Andrey Andreev | 303eef0 | 2012-11-06 14:55:48 +0200 | [diff] [blame] | 64 | With CodeIgniter's built in methods you can simply do this:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 65 | |
| 66 | $something = $this->input->post('something'); |
| 67 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 68 | The main methods are: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 69 | |
| 70 | - $this->input->post() |
Andrey Andreev | 22c3e73 | 2012-06-13 10:21:36 +0300 | [diff] [blame] | 71 | - $this->input->get() |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 72 | - $this->input->cookie() |
| 73 | - $this->input->server() |
| 74 | |
Andrey Andreev | 303eef0 | 2012-11-06 14:55:48 +0200 | [diff] [blame] | 75 | Using the php://input stream |
| 76 | ============================ |
| 77 | |
| 78 | If you want to utilize the PUT, DELETE, PATCH or other exotic request |
| 79 | methods, they can only be accessed via a special input stream, that |
| 80 | can only be read once. This isn't as easy as just reading from e.g. |
| 81 | the ``$_POST`` array, because it will always exist and you can try |
| 82 | and access multiple variables without caring that you might only have |
| 83 | one shot at all of the POST data. |
| 84 | |
| 85 | CodeIgniter will take care of that for you, and you can access data |
| 86 | from the **php://input** stream at any time, just by calling the |
| 87 | ``input_stream()`` method:: |
| 88 | |
| 89 | $this->input->input_stream('key'); |
| 90 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 91 | Similar to other methods such as ``get()`` and ``post()``, if the |
| 92 | requested data is not found, it will return NULL and you can also |
| 93 | decide whether to run the data through ``xss_clean()`` by passing |
| 94 | a boolean value as the second parameter:: |
Andrey Andreev | 303eef0 | 2012-11-06 14:55:48 +0200 | [diff] [blame] | 95 | |
| 96 | $this->input->input_stream('key', TRUE); // XSS Clean |
| 97 | $this->input->input_stream('key', FALSE); // No XSS filter |
| 98 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 99 | .. note:: You can utilize ``method()`` in order to know if you're reading |
Andrey Andreev | 303eef0 | 2012-11-06 14:55:48 +0200 | [diff] [blame] | 100 | PUT, DELETE or PATCH data. |
| 101 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 102 | *************** |
| 103 | Class Reference |
| 104 | *************** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 105 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 106 | .. class:: CI_Input |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 107 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 108 | .. method:: post([$index = NULL[, $xss_clean = FALSE]]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 109 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 110 | :param string $index: POST parameter name |
| 111 | :param bool $xss_clean: Whether to apply XSS filtering |
| 112 | :returns: mixed |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 113 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 114 | The first parameter will contain the name of the POST item you are |
| 115 | looking for:: |
Derek Jones | 8831d11 | 2011-10-05 15:57:02 -0500 | [diff] [blame] | 116 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 117 | $this->input->post('some_data'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 118 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 119 | The method returns NULL if the item you are attempting to retrieve |
| 120 | does not exist. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 121 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 122 | The second optional parameter lets you run the data through the XSS |
| 123 | filter. It's enabled by setting the second parameter to boolean TRUE. |
| 124 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 125 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 126 | $this->input->post('some_data', TRUE); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 127 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 128 | To return an array of all POST items call without any parameters. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 129 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 130 | To return all POST items and pass them through the XSS filter set the |
| 131 | first parameter NULL while setting the second parameter to boolean TRUE. |
| 132 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 133 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 134 | $this->input->post(NULL, TRUE); // returns all POST items with XSS filter |
| 135 | $this->input->post(); // returns all POST items without XSS filter |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 136 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 137 | .. method:: get([$index = NULL[, $xss_clean = FALSE]]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 138 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 139 | :param string $index: GET parameter name |
| 140 | :param bool $xss_clean: Whether to apply XSS filtering |
| 141 | :returns: mixed |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 142 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 143 | This method is identical to ``post()``, only it fetches GET data. |
| 144 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 145 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 146 | $this->input->get('some_data', TRUE); |
| 147 | |
| 148 | To return an array of all GET items call without any parameters. |
| 149 | |
| 150 | To return all GET items and pass them through the XSS filter set the |
| 151 | first parameter NULL while setting the second parameter to boolean TRUE. |
| 152 | :: |
| 153 | |
| 154 | $this->input->get(NULL, TRUE); // returns all GET items with XSS filter |
| 155 | $this->input->get(); // returns all GET items without XSS filtering |
| 156 | |
| 157 | .. method:: get_post([$index = ''[, $xss_clean = FALSE]]) |
| 158 | |
| 159 | :param string $index: GET/POST parameter name |
| 160 | :param bool $xss_clean: Whether to apply XSS filtering |
| 161 | :returns: mixed |
| 162 | |
| 163 | This method works the same way as ``post()`` and ``get()``, only combined. |
| 164 | It will search through both POST and GET streams for data, looking first |
| 165 | in POST, and then in GET:: |
| 166 | |
| 167 | $this->input->get_post('some_data', TRUE); |
| 168 | |
| 169 | .. method:: cookie([$index = ''[, $xss_clean = FALSE]]) |
| 170 | |
| 171 | :param string $index: COOKIE parameter name |
| 172 | :param bool $xss_clean: Whether to apply XSS filtering |
| 173 | :returns: mixed |
| 174 | |
| 175 | This method is identical to ``post()`` and ``get()``, only it fetches cookie |
| 176 | data:: |
| 177 | |
| 178 | $this->input->cookie('some_cookie'); |
| 179 | $this->input->cookie('some_cookie, TRUE); // with XSS filter |
| 180 | |
| 181 | .. method:: server([$index = ''[, $xss_clean = FALSE]]) |
| 182 | |
| 183 | :param string $index: Value name |
| 184 | :param bool $xss_clean: Whether to apply XSS filtering |
| 185 | :returns: mixed |
| 186 | |
| 187 | This method is identical to the ``post()``, ``get()`` and ``cookie()`` methods, |
| 188 | only it fetches server data (``$_SERVER``):: |
| 189 | |
| 190 | $this->input->server('some_data'); |
| 191 | |
| 192 | .. method:: input_stream([$index = ''[, $xss_clean = FALSE]]) |
| 193 | |
| 194 | :param string $index: Key name |
| 195 | :param bool $xss_clean: Whether to apply XSS filtering |
| 196 | :returns: mixed |
| 197 | |
| 198 | This method is identical to ``get()``, ``post()`` and ``cookie()``, |
| 199 | only it fetches the *php://input* stream data. |
| 200 | |
| 201 | .. method:: set_cookie($name = ''[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = FALSE[, $httponly = FALSE]]]]]]]) |
| 202 | |
| 203 | :param mixed $name: Cookie name or an array of parameters |
| 204 | :param string $value: Cookie value |
| 205 | :param int $expire: Cookie expiration time in seconds |
| 206 | :param string $domain: Cookie domain |
| 207 | :param string $path: Cookie path |
| 208 | :param string $prefix: Cookie name prefix |
| 209 | :param bool $secure: Whether to only transfer the cookie through HTTPS |
| 210 | :param bool $httponly: Whether to only make the cookie accessible for HTTP requests (no JavaScript) |
| 211 | :returns: void |
| 212 | |
| 213 | Sets a cookie containing the values you specify. There are two ways to |
| 214 | pass information to this method so that a cookie can be set: Array |
| 215 | Method, and Discrete Parameters: |
| 216 | |
| 217 | Array Method |
| 218 | ^^^^^^^^^^^^ |
| 219 | |
| 220 | Using this method, an associative array is passed to the first |
| 221 | parameter:: |
| 222 | |
| 223 | $cookie = array( |
| 224 | 'name' => 'The Cookie Name', |
| 225 | 'value' => 'The Value', |
| 226 | 'expire' => '86500', |
| 227 | 'domain' => '.some-domain.com', |
| 228 | 'path' => '/', |
| 229 | 'prefix' => 'myprefix_', |
| 230 | 'secure' => TRUE |
| 231 | ); |
| 232 | |
| 233 | $this->input->set_cookie($cookie); |
| 234 | |
| 235 | **Notes:** |
| 236 | |
| 237 | Only the name and value are required. To delete a cookie set it with the |
| 238 | expiration blank. |
| 239 | |
| 240 | The expiration is set in **seconds**, which will be added to the current |
| 241 | time. Do not include the time, but rather only the number of seconds |
| 242 | from *now* that you wish the cookie to be valid. If the expiration is |
| 243 | set to zero the cookie will only last as long as the browser is open. |
| 244 | |
| 245 | For site-wide cookies regardless of how your site is requested, add your |
| 246 | URL to the **domain** starting with a period, like this: |
| 247 | .your-domain.com |
| 248 | |
| 249 | The path is usually not needed since the method sets a root path. |
| 250 | |
| 251 | The prefix is only needed if you need to avoid name collisions with |
| 252 | other identically named cookies for your server. |
| 253 | |
| 254 | The secure boolean is only needed if you want to make it a secure cookie |
| 255 | by setting it to TRUE. |
| 256 | |
| 257 | Discrete Parameters |
| 258 | ^^^^^^^^^^^^^^^^^^^ |
| 259 | |
| 260 | If you prefer, you can set the cookie by passing data using individual |
| 261 | parameters:: |
| 262 | |
| 263 | $this->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 264 | |
Andrey Andreev | 303eef0 | 2012-11-06 14:55:48 +0200 | [diff] [blame] | 265 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 266 | .. method:: ip_address() |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 267 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 268 | :returns: string |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 269 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 270 | Returns the IP address for the current user. If the IP address is not |
| 271 | valid, the method will return '0.0.0.0':: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 272 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 273 | echo $this->input->ip_address(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 274 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 275 | .. important:: This method takes into account the ``$config['proxy_ips']`` |
| 276 | setting and will return the reported HTTP_X_FORWARDED_FOR, |
| 277 | HTTP_CLIENT_IP, HTTP_X_CLIENT_IP or HTTP_X_CLUSTER_CLIENT_IP |
| 278 | address for the allowed IP addresses. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 279 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 280 | .. method:: valid_ip($ip[, $which = '']) |
Andrey Andreev | 303eef0 | 2012-11-06 14:55:48 +0200 | [diff] [blame] | 281 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 282 | :param string $ip: IP address |
| 283 | :param string $which: IP protocol ('ipv4' or 'ipv6') |
| 284 | :returns: bool |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 285 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 286 | Takes an IP address as input and returns TRUE or FALSE (boolean) depending |
| 287 | on whether it is valid or not. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 288 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 289 | .. note:: The $this->input->ip_address() method above automatically |
| 290 | validates the IP address. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 291 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 292 | :: |
Andrey Andreev | 5a25718 | 2012-06-10 06:18:14 +0300 | [diff] [blame] | 293 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 294 | if ( ! $this->input->valid_ip($ip)) |
| 295 | { |
| 296 | echo 'Not Valid'; |
| 297 | } |
| 298 | else |
| 299 | { |
| 300 | echo 'Valid'; |
| 301 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 302 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 303 | Accepts an optional second string parameter of 'ipv4' or 'ipv6' to specify |
| 304 | an IP format. The default checks for both formats. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 305 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 306 | .. method:: user_agent() |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 307 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 308 | :returns: string |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 309 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 310 | Returns the user agent string (web browser) being used by the current user, |
| 311 | or NULL if it's not available. |
| 312 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 313 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 314 | echo $this->input->user_agent(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 315 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 316 | See the :doc:`User Agent Class <user_agent>` for methods which extract |
| 317 | information from the user agent string. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 318 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 319 | .. method:: request_headers([$xss_clean = FALSE]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 320 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 321 | :param bool $xss_clean: Whether to apply XSS filtering |
| 322 | :returns: array |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 323 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 324 | Returns an array of HTTP request headers. |
| 325 | Useful if running in a non-Apache environment where |
| 326 | `apache_request_headers() <http://php.net/apache_request_headers>`_ |
| 327 | will not be supported. |
| 328 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 329 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 330 | $headers = $this->input->request_headers(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 331 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 332 | .. method:: get_request_header($index[, $xss_clean = FALSE]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 333 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 334 | :param string $index: HTTP request header name |
| 335 | :param bool $xss_clean: Whether to apply XSS filtering |
| 336 | :returns: string |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 337 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 338 | Returns a single member of the request headers array or NULL |
| 339 | if the searched header is not found. |
| 340 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 341 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 342 | $this->input->get_request_header('some-header', TRUE); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 343 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 344 | .. method:: is_ajax_request() |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 345 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 346 | :returns: bool |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 347 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 348 | Checks to see if the HTTP_X_REQUESTED_WITH server header has been |
| 349 | set, and returns boolean TRUE if it is or FALSE if not. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 350 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 351 | .. method:: is_cli_request() |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 352 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 353 | :returns: bool |
Michiel Vugteveen | be0ca26 | 2012-03-07 19:09:51 +0100 | [diff] [blame] | 354 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 355 | Checks to see if the application was run from the command-line |
| 356 | interface. |
Michiel Vugteveen | be0ca26 | 2012-03-07 19:09:51 +0100 | [diff] [blame] | 357 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 358 | .. note:: This method checks both the PHP SAPI name currently in use |
| 359 | and if the ``STDIN`` constant is defined, which is usually a |
| 360 | failsafe way to see if PHP is being run via the command line. |
Michiel Vugteveen | be0ca26 | 2012-03-07 19:09:51 +0100 | [diff] [blame] | 361 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 362 | :: |
| 363 | |
| 364 | $this->input->is_cli_request() |
| 365 | |
| 366 | .. method:: method([$upper = FALSE]) |
| 367 | |
| 368 | :param bool $upper: Whether to return the request method name in upper or lower case |
| 369 | :returns: string |
| 370 | |
| 371 | Returns the ``$_SERVER['REQUEST_METHOD']``, with the option to set it |
| 372 | in uppercase or lowercase. |
| 373 | :: |
| 374 | |
| 375 | echo $this->input->method(TRUE); // Outputs: POST |
| 376 | echo $this->input->method(FALSE); // Outputs: post |
| 377 | echo $this->input->method(); // Outputs: post |