PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/system/core/Input.php

https://github.com/betchi/CodeIgniter
PHP | 838 lines | 408 code | 106 blank | 324 comment | 64 complexity | e705203c57bddac94aef5c8595e97345 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. <?php
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.2.4 or newer
  6. *
  7. * NOTICE OF LICENSE
  8. *
  9. * Licensed under the Open Software License version 3.0
  10. *
  11. * This source file is subject to the Open Software License (OSL 3.0) that is
  12. * bundled with this package in the files license.txt / license.rst. It is
  13. * also available through the world wide web at this URL:
  14. * http://opensource.org/licenses/OSL-3.0
  15. * If you did not receive a copy of the license and are unable to obtain it
  16. * through the world wide web, please send an email to
  17. * licensing@ellislab.com so we can send you a copy immediately.
  18. *
  19. * @package CodeIgniter
  20. * @author EllisLab Dev Team
  21. * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
  22. * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
  23. * @link http://codeigniter.com
  24. * @since Version 1.0
  25. * @filesource
  26. */
  27. defined('BASEPATH') OR exit('No direct script access allowed');
  28. /**
  29. * Input Class
  30. *
  31. * Pre-processes global input data for security
  32. *
  33. * @package CodeIgniter
  34. * @subpackage Libraries
  35. * @category Input
  36. * @author EllisLab Dev Team
  37. * @link http://codeigniter.com/user_guide/libraries/input.html
  38. */
  39. class CI_Input {
  40. /**
  41. * IP address of the current user
  42. *
  43. * @var string
  44. */
  45. public $ip_address = FALSE;
  46. /**
  47. * Allow GET array flag
  48. *
  49. * If set to FALSE, then $_GET will be set to an empty array.
  50. *
  51. * @var bool
  52. */
  53. protected $_allow_get_array = TRUE;
  54. /**
  55. * Standardize new lines flag
  56. *
  57. * If set to TRUE, then newlines are standardized.
  58. *
  59. * @var bool
  60. */
  61. protected $_standardize_newlines;
  62. /**
  63. * Enable XSS flag
  64. *
  65. * Determines whether the XSS filter is always active when
  66. * GET, POST or COOKIE data is encountered.
  67. * Set automatically based on config setting.
  68. *
  69. * @var bool
  70. */
  71. protected $_enable_xss = FALSE;
  72. /**
  73. * Enable CSRF flag
  74. *
  75. * Enables a CSRF cookie token to be set.
  76. * Set automatically based on config setting.
  77. *
  78. * @var bool
  79. */
  80. protected $_enable_csrf = FALSE;
  81. /**
  82. * List of all HTTP request headers
  83. *
  84. * @var array
  85. */
  86. protected $headers = array();
  87. /**
  88. * Input stream data
  89. *
  90. * Parsed from php://input at runtime
  91. *
  92. * @see CI_Input::input_stream()
  93. * @var array
  94. */
  95. protected $_input_stream = NULL;
  96. /**
  97. * Class constructor
  98. *
  99. * Determines whether to globally enable the XSS processing
  100. * and whether to allow the $_GET array.
  101. *
  102. * @return void
  103. */
  104. public function __construct()
  105. {
  106. log_message('debug', 'Input Class Initialized');
  107. $this->_allow_get_array = (config_item('allow_get_array') === TRUE);
  108. $this->_enable_xss = (config_item('global_xss_filtering') === TRUE);
  109. $this->_enable_csrf = (config_item('csrf_protection') === TRUE);
  110. $this->_standardize_newlines = (bool) config_item('standardize_newlines');
  111. $this->security =& load_class('Security', 'core');
  112. // Do we need the UTF-8 class?
  113. if (UTF8_ENABLED === TRUE)
  114. {
  115. $this->uni =& load_class('Utf8', 'core');
  116. }
  117. // Sanitize global arrays
  118. $this->_sanitize_globals();
  119. }
  120. // --------------------------------------------------------------------
  121. /**
  122. * Fetch from array
  123. *
  124. * Internal method used to retrieve values from global arrays.
  125. *
  126. * @param array &$array $_GET, $_POST, $_COOKIE, $_SERVER, etc.
  127. * @param string $index Index for item to be fetched from $array
  128. * @param bool $xss_clean Whether to apply XSS filtering
  129. * @return mixed
  130. */
  131. protected function _fetch_from_array(&$array, $index = NULL, $xss_clean = NULL)
  132. {
  133. // If $index is NULL, it means that the whole $array is requested
  134. if ($index === NULL)
  135. {
  136. $output = array();
  137. foreach (array_keys($array) as $key)
  138. {
  139. $output[$key] = $this->_fetch_from_array($array, $key, $xss_clean);
  140. }
  141. return $output;
  142. }
  143. is_bool($xss_clean) OR $xss_clean = $this->_enable_xss;
  144. if (isset($array[$index]))
  145. {
  146. $value = $array[$index];
  147. }
  148. elseif (($count = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $index, $matches)) > 1) // Does the index contain array notation
  149. {
  150. $value = $array;
  151. for ($i = 0; $i < $count; $i++)
  152. {
  153. $key = trim($matches[0][$i], '[]');
  154. if ($key === '') // Empty notation will return the value as array
  155. {
  156. break;
  157. }
  158. if (isset($value[$key]))
  159. {
  160. $value = $value[$key];
  161. }
  162. else
  163. {
  164. return NULL;
  165. }
  166. }
  167. }
  168. else
  169. {
  170. return NULL;
  171. }
  172. return ($xss_clean === TRUE)
  173. ? $this->security->xss_clean($value)
  174. : $value;
  175. }
  176. // --------------------------------------------------------------------
  177. /**
  178. * Fetch an item from the GET array
  179. *
  180. * @param string $index Index for item to be fetched from $_GET
  181. * @param bool $xss_clean Whether to apply XSS filtering
  182. * @return mixed
  183. */
  184. public function get($index = NULL, $xss_clean = NULL)
  185. {
  186. return $this->_fetch_from_array($_GET, $index, $xss_clean);
  187. }
  188. // --------------------------------------------------------------------
  189. /**
  190. * Fetch an item from the POST array
  191. *
  192. * @param string $index Index for item to be fetched from $_POST
  193. * @param bool $xss_clean Whether to apply XSS filtering
  194. * @return mixed
  195. */
  196. public function post($index = NULL, $xss_clean = NULL)
  197. {
  198. return $this->_fetch_from_array($_POST, $index, $xss_clean);
  199. }
  200. // --------------------------------------------------------------------
  201. /**
  202. * Fetch an item from POST data with fallback to GET
  203. *
  204. * @param string $index Index for item to be fetched from $_POST or $_GET
  205. * @param bool $xss_clean Whether to apply XSS filtering
  206. * @return mixed
  207. */
  208. public function post_get($index, $xss_clean = NULL)
  209. {
  210. return isset($_POST[$index])
  211. ? $this->post($index, $xss_clean)
  212. : $this->get($index, $xss_clean);
  213. }
  214. // --------------------------------------------------------------------
  215. /**
  216. * Fetch an item from GET data with fallback to POST
  217. *
  218. * @param string $index Index for item to be fetched from $_GET or $_POST
  219. * @param bool $xss_clean Whether to apply XSS filtering
  220. * @return mixed
  221. */
  222. public function get_post($index, $xss_clean = NULL)
  223. {
  224. return isset($_GET[$index])
  225. ? $this->get($index, $xss_clean)
  226. : $this->post($index, $xss_clean);
  227. }
  228. // --------------------------------------------------------------------
  229. /**
  230. * Fetch an item from the COOKIE array
  231. *
  232. * @param string $index Index for item to be fetched from $_COOKIE
  233. * @param bool $xss_clean Whether to apply XSS filtering
  234. * @return mixed
  235. */
  236. public function cookie($index = NULL, $xss_clean = NULL)
  237. {
  238. return $this->_fetch_from_array($_COOKIE, $index, $xss_clean);
  239. }
  240. // --------------------------------------------------------------------
  241. /**
  242. * Fetch an item from the SERVER array
  243. *
  244. * @param string $index Index for item to be fetched from $_SERVER
  245. * @param bool $xss_clean Whether to apply XSS filtering
  246. * @return mixed
  247. */
  248. public function server($index, $xss_clean = NULL)
  249. {
  250. return $this->_fetch_from_array($_SERVER, $index, $xss_clean);
  251. }
  252. // ------------------------------------------------------------------------
  253. /**
  254. * Fetch an item from the php://input stream
  255. *
  256. * Useful when you need to access PUT, DELETE or PATCH request data.
  257. *
  258. * @param string $index Index for item to be fetched
  259. * @param bool $xss_clean Whether to apply XSS filtering
  260. * @return mixed
  261. */
  262. public function input_stream($index = NULL, $xss_clean = NULL)
  263. {
  264. // Prior to PHP 5.6, the input stream can only be read once,
  265. // so we'll need to check if we have already done that first.
  266. if ( ! is_array($this->_input_stream))
  267. {
  268. parse_str(file_get_contents('php://input'), $this->_input_stream);
  269. is_array($this->_input_stream) OR $this->_input_stream = array();
  270. }
  271. return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean);
  272. }
  273. // ------------------------------------------------------------------------
  274. /**
  275. * Set cookie
  276. *
  277. * Accepts an arbitrary number of parameters (up to 7) or an associative
  278. * array in the first parameter containing all the values.
  279. *
  280. * @param string|mixed[] $name Cookie name or an array containing parameters
  281. * @param string $value Cookie value
  282. * @param int $expire Cookie expiration time in seconds
  283. * @param string $domain Cookie domain (e.g.: '.yourdomain.com')
  284. * @param string $path Cookie path (default: '/')
  285. * @param string $prefix Cookie name prefix
  286. * @param bool $secure Whether to only transfer cookies via SSL
  287. * @param bool $httponly Whether to only makes the cookie accessible via HTTP (no javascript)
  288. * @return void
  289. */
  290. public function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE, $httponly = FALSE)
  291. {
  292. if (is_array($name))
  293. {
  294. // always leave 'name' in last place, as the loop will break otherwise, due to $$item
  295. foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'httponly', 'name') as $item)
  296. {
  297. if (isset($name[$item]))
  298. {
  299. $$item = $name[$item];
  300. }
  301. }
  302. }
  303. if ($prefix === '' && config_item('cookie_prefix') !== '')
  304. {
  305. $prefix = config_item('cookie_prefix');
  306. }
  307. if ($domain == '' && config_item('cookie_domain') != '')
  308. {
  309. $domain = config_item('cookie_domain');
  310. }
  311. if ($path === '/' && config_item('cookie_path') !== '/')
  312. {
  313. $path = config_item('cookie_path');
  314. }
  315. if ($secure === FALSE && config_item('cookie_secure') !== FALSE)
  316. {
  317. $secure = config_item('cookie_secure');
  318. }
  319. if ($httponly === FALSE && config_item('cookie_httponly') !== FALSE)
  320. {
  321. $httponly = config_item('cookie_httponly');
  322. }
  323. if ( ! is_numeric($expire))
  324. {
  325. $expire = time() - 86500;
  326. }
  327. else
  328. {
  329. $expire = ($expire > 0) ? time() + $expire : 0;
  330. }
  331. setcookie($prefix.$name, $value, $expire, $path, $domain, $secure, $httponly);
  332. }
  333. // --------------------------------------------------------------------
  334. /**
  335. * Fetch the IP Address
  336. *
  337. * Determines and validates the visitor's IP address.
  338. *
  339. * @return string IP address
  340. */
  341. public function ip_address()
  342. {
  343. if ($this->ip_address !== FALSE)
  344. {
  345. return $this->ip_address;
  346. }
  347. $proxy_ips = config_item('proxy_ips');
  348. if ( ! empty($proxy_ips) && ! is_array($proxy_ips))
  349. {
  350. $proxy_ips = explode(',', str_replace(' ', '', $proxy_ips));
  351. }
  352. $this->ip_address = $this->server('REMOTE_ADDR');
  353. if ($proxy_ips)
  354. {
  355. foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP') as $header)
  356. {
  357. if (($spoof = $this->server($header)) !== NULL)
  358. {
  359. // Some proxies typically list the whole chain of IP
  360. // addresses through which the client has reached us.
  361. // e.g. client_ip, proxy_ip1, proxy_ip2, etc.
  362. sscanf($spoof, '%[^,]', $spoof);
  363. if ( ! $this->valid_ip($spoof))
  364. {
  365. $spoof = NULL;
  366. }
  367. else
  368. {
  369. break;
  370. }
  371. }
  372. }
  373. if ($spoof)
  374. {
  375. for ($i = 0, $c = count($proxy_ips); $i < $c; $i++)
  376. {
  377. // Check if we have an IP address or a subnet
  378. if (strpos($proxy_ips[$i], '/') === FALSE)
  379. {
  380. // An IP address (and not a subnet) is specified.
  381. // We can compare right away.
  382. if ($proxy_ips[$i] === $this->ip_address)
  383. {
  384. $this->ip_address = $spoof;
  385. break;
  386. }
  387. continue;
  388. }
  389. // We have a subnet ... now the heavy lifting begins
  390. isset($separator) OR $separator = $this->valid_ip($this->ip_address, 'ipv6') ? ':' : '.';
  391. // If the proxy entry doesn't match the IP protocol - skip it
  392. if (strpos($proxy_ips[$i], $separator) === FALSE)
  393. {
  394. continue;
  395. }
  396. // Convert the REMOTE_ADDR IP address to binary, if needed
  397. if ( ! isset($ip, $sprintf))
  398. {
  399. if ($separator === ':')
  400. {
  401. // Make sure we're have the "full" IPv6 format
  402. $ip = explode(':',
  403. str_replace('::',
  404. str_repeat(':', 9 - substr_count($this->ip_address, ':')),
  405. $this->ip_address
  406. )
  407. );
  408. for ($i = 0; $i < 8; $i++)
  409. {
  410. $ip[$i] = intval($ip[$i], 16);
  411. }
  412. $sprintf = '%016b%016b%016b%016b%016b%016b%016b%016b';
  413. }
  414. else
  415. {
  416. $ip = explode('.', $this->ip_address);
  417. $sprintf = '%08b%08b%08b%08b';
  418. }
  419. $ip = vsprintf($sprintf, $ip);
  420. }
  421. // Split the netmask length off the network address
  422. sscanf($proxy_ips[$i], '%[^/]/%d', $netaddr, $masklen);
  423. // Again, an IPv6 address is most likely in a compressed form
  424. if ($separator === ':')
  425. {
  426. $netaddr = explode(':', str_replace('::', str_repeat(':', 9 - substr_count($netaddr, ':')), $netaddr));
  427. for ($i = 0; $i < 8; $i++)
  428. {
  429. $netaddr[$i] = intval($netaddr[$i], 16);
  430. }
  431. }
  432. else
  433. {
  434. $netaddr = explode('.', $netaddr);
  435. }
  436. // Convert to binary and finally compare
  437. if (strncmp($ip, vsprintf($sprintf, $netaddr), $masklen) === 0)
  438. {
  439. $this->ip_address = $spoof;
  440. break;
  441. }
  442. }
  443. }
  444. }
  445. if ( ! $this->valid_ip($this->ip_address))
  446. {
  447. return $this->ip_address = '0.0.0.0';
  448. }
  449. return $this->ip_address;
  450. }
  451. // --------------------------------------------------------------------
  452. /**
  453. * Validate IP Address
  454. *
  455. * @param string $ip IP address
  456. * @param string $which IP protocol: 'ipv4' or 'ipv6'
  457. * @return bool
  458. */
  459. public function valid_ip($ip, $which = '')
  460. {
  461. switch (strtolower($which))
  462. {
  463. case 'ipv4':
  464. $which = FILTER_FLAG_IPV4;
  465. break;
  466. case 'ipv6':
  467. $which = FILTER_FLAG_IPV6;
  468. break;
  469. default:
  470. $which = NULL;
  471. break;
  472. }
  473. return (bool) filter_var($ip, FILTER_VALIDATE_IP, $which);
  474. }
  475. // --------------------------------------------------------------------
  476. /**
  477. * Fetch User Agent string
  478. *
  479. * @return string|null User Agent string or NULL if it doesn't exist
  480. */
  481. public function user_agent($xss_clean = NULL)
  482. {
  483. return $this->_fetch_from_array($_SERVER, 'HTTP_USER_AGENT', $xss_clean);
  484. }
  485. // --------------------------------------------------------------------
  486. /**
  487. * Sanitize Globals
  488. *
  489. * Internal method serving for the following purposes:
  490. *
  491. * - Unsets $_GET data, if query strings are not enabled
  492. * - Cleans POST, COOKIE and SERVER data
  493. * - Standardizes newline characters to PHP_EOL
  494. *
  495. * @return void
  496. */
  497. protected function _sanitize_globals()
  498. {
  499. // Is $_GET data allowed? If not we'll set the $_GET to an empty array
  500. if ($this->_allow_get_array === FALSE)
  501. {
  502. $_GET = array();
  503. }
  504. elseif (is_array($_GET) && count($_GET) > 0)
  505. {
  506. foreach ($_GET as $key => $val)
  507. {
  508. $_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
  509. }
  510. }
  511. // Clean $_POST Data
  512. if (is_array($_POST) && count($_POST) > 0)
  513. {
  514. foreach ($_POST as $key => $val)
  515. {
  516. $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
  517. }
  518. }
  519. // Clean $_COOKIE Data
  520. if (is_array($_COOKIE) && count($_COOKIE) > 0)
  521. {
  522. // Also get rid of specially treated cookies that might be set by a server
  523. // or silly application, that are of no use to a CI application anyway
  524. // but that when present will trip our 'Disallowed Key Characters' alarm
  525. // http://www.ietf.org/rfc/rfc2109.txt
  526. // note that the key names below are single quoted strings, and are not PHP variables
  527. unset(
  528. $_COOKIE['$Version'],
  529. $_COOKIE['$Path'],
  530. $_COOKIE['$Domain']
  531. );
  532. foreach ($_COOKIE as $key => $val)
  533. {
  534. if (($cookie_key = $this->_clean_input_keys($key)) !== FALSE)
  535. {
  536. $_COOKIE[$cookie_key] = $this->_clean_input_data($val);
  537. }
  538. else
  539. {
  540. unset($_COOKIE[$key]);
  541. }
  542. }
  543. }
  544. // Sanitize PHP_SELF
  545. $_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
  546. // CSRF Protection check
  547. if ($this->_enable_csrf === TRUE && ! is_cli())
  548. {
  549. $this->security->csrf_verify();
  550. }
  551. log_message('debug', 'Global POST, GET and COOKIE data sanitized');
  552. }
  553. // --------------------------------------------------------------------
  554. /**
  555. * Clean Input Data
  556. *
  557. * Internal method that aids in escaping data and
  558. * standardizing newline characters to PHP_EOL.
  559. *
  560. * @param string|string[] $str Input string(s)
  561. * @return string
  562. */
  563. protected function _clean_input_data($str)
  564. {
  565. if (is_array($str))
  566. {
  567. $new_array = array();
  568. foreach (array_keys($str) as $key)
  569. {
  570. $new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($str[$key]);
  571. }
  572. return $new_array;
  573. }
  574. /* We strip slashes if magic quotes is on to keep things consistent
  575. NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and
  576. it will probably not exist in future versions at all.
  577. */
  578. if ( ! is_php('5.4') && get_magic_quotes_gpc())
  579. {
  580. $str = stripslashes($str);
  581. }
  582. // Clean UTF-8 if supported
  583. if (UTF8_ENABLED === TRUE)
  584. {
  585. $str = $this->uni->clean_string($str);
  586. }
  587. // Remove control characters
  588. $str = remove_invisible_characters($str, FALSE);
  589. // Standardize newlines if needed
  590. if ($this->_standardize_newlines === TRUE)
  591. {
  592. return preg_replace('/(?:\r\n|[\r\n])/', PHP_EOL, $str);
  593. }
  594. return $str;
  595. }
  596. // --------------------------------------------------------------------
  597. /**
  598. * Clean Keys
  599. *
  600. * Internal method that helps to prevent malicious users
  601. * from trying to exploit keys we make sure that keys are
  602. * only named with alpha-numeric text and a few other items.
  603. *
  604. * @param string $str Input string
  605. * @param string $fatal Whether to terminate script exection
  606. * or to return FALSE if an invalid
  607. * key is encountered
  608. * @return string|bool
  609. */
  610. protected function _clean_input_keys($str, $fatal = TRUE)
  611. {
  612. if ( ! preg_match('/^[a-z0-9:_\/|-]+$/i', $str))
  613. {
  614. if ($fatal === TRUE)
  615. {
  616. return FALSE;
  617. }
  618. else
  619. {
  620. set_status_header(503);
  621. echo 'Disallowed Key Characters.';
  622. exit(7); // EXIT_USER_INPUT
  623. }
  624. }
  625. // Clean UTF-8 if supported
  626. if (UTF8_ENABLED === TRUE)
  627. {
  628. return $this->uni->clean_string($str);
  629. }
  630. return $str;
  631. }
  632. // --------------------------------------------------------------------
  633. /**
  634. * Request Headers
  635. *
  636. * @param bool $xss_clean Whether to apply XSS filtering
  637. * @return array
  638. */
  639. public function request_headers($xss_clean = FALSE)
  640. {
  641. // If header is already defined, return it immediately
  642. if ( ! empty($this->headers))
  643. {
  644. return $this->headers;
  645. }
  646. // In Apache, you can simply call apache_request_headers()
  647. if (function_exists('apache_request_headers'))
  648. {
  649. return $this->headers = apache_request_headers();
  650. }
  651. $this->headers['Content-Type'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE');
  652. foreach ($_SERVER as $key => $val)
  653. {
  654. if (sscanf($key, 'HTTP_%s', $header) === 1)
  655. {
  656. // take SOME_HEADER and turn it into Some-Header
  657. $header = str_replace('_', ' ', strtolower($header));
  658. $header = str_replace(' ', '-', ucwords($header));
  659. $this->headers[$header] = $this->_fetch_from_array($_SERVER, $key, $xss_clean);
  660. }
  661. }
  662. return $this->headers;
  663. }
  664. // --------------------------------------------------------------------
  665. /**
  666. * Get Request Header
  667. *
  668. * Returns the value of a single member of the headers class member
  669. *
  670. * @param string $index Header name
  671. * @param bool $xss_clean Whether to apply XSS filtering
  672. * @return string|bool The requested header on success or FALSE on failure
  673. */
  674. public function get_request_header($index, $xss_clean = FALSE)
  675. {
  676. if (empty($this->headers))
  677. {
  678. $this->request_headers();
  679. }
  680. if ( ! isset($this->headers[$index]))
  681. {
  682. return NULL;
  683. }
  684. return ($xss_clean === TRUE)
  685. ? $this->security->xss_clean($this->headers[$index])
  686. : $this->headers[$index];
  687. }
  688. // --------------------------------------------------------------------
  689. /**
  690. * Is AJAX request?
  691. *
  692. * Test to see if a request contains the HTTP_X_REQUESTED_WITH header.
  693. *
  694. * @return bool
  695. */
  696. public function is_ajax_request()
  697. {
  698. return ( ! empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
  699. }
  700. // --------------------------------------------------------------------
  701. /**
  702. * Is CLI request?
  703. *
  704. * Test to see if a request was made from the command line.
  705. *
  706. * @deprecated 3.0.0 Use is_cli() instead
  707. * @return bool
  708. */
  709. public function is_cli_request()
  710. {
  711. return is_cli();
  712. }
  713. // --------------------------------------------------------------------
  714. /**
  715. * Get Request Method
  716. *
  717. * Return the request method
  718. *
  719. * @param bool $upper Whether to return in upper or lower case
  720. * (default: FALSE)
  721. * @return string
  722. */
  723. public function method($upper = FALSE)
  724. {
  725. return ($upper)
  726. ? strtoupper($this->server('REQUEST_METHOD'))
  727. : strtolower($this->server('REQUEST_METHOD'));
  728. }
  729. }
  730. /* End of file Input.php */
  731. /* Location: ./system/core/Input.php */