Input.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.1.6 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author EllisLab Dev Team
  9. * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc.
  10. * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
  11. * @license http://codeigniter.com/user_guide/license.html
  12. * @link http://codeigniter.com
  13. * @since Version 1.0
  14. * @filesource
  15. */
  16. // ------------------------------------------------------------------------
  17. /**
  18. * Input Class
  19. *
  20. * Pre-processes global input data for security
  21. *
  22. * @package CodeIgniter
  23. * @subpackage Libraries
  24. * @category Input
  25. * @author EllisLab Dev Team
  26. * @link http://codeigniter.com/user_guide/libraries/input.html
  27. */
  28. class CI_Input {
  29. /**
  30. * IP address of the current user
  31. *
  32. * @var string
  33. */
  34. var $ip_address = FALSE;
  35. /**
  36. * user agent (web browser) being used by the current user
  37. *
  38. * @var string
  39. */
  40. var $user_agent = FALSE;
  41. /**
  42. * If FALSE, then $_GET will be set to an empty array
  43. *
  44. * @var bool
  45. */
  46. var $_allow_get_array = TRUE;
  47. /**
  48. * If TRUE, then newlines are standardized
  49. *
  50. * @var bool
  51. */
  52. var $_standardize_newlines = TRUE;
  53. /**
  54. * Determines whether the XSS filter is always active when GET, POST or COOKIE data is encountered
  55. * Set automatically based on config setting
  56. *
  57. * @var bool
  58. */
  59. var $_enable_xss = FALSE;
  60. /**
  61. * Enables a CSRF cookie token to be set.
  62. * Set automatically based on config setting
  63. *
  64. * @var bool
  65. */
  66. var $_enable_csrf = FALSE;
  67. /**
  68. * List of all HTTP request headers
  69. *
  70. * @var array
  71. */
  72. protected $headers = array();
  73. /**
  74. * Constructor
  75. *
  76. * Sets whether to globally enable the XSS processing
  77. * and whether to allow the $_GET array
  78. *
  79. * @return void
  80. */
  81. public function __construct()
  82. {
  83. log_message('debug', "Input Class Initialized");
  84. $this->_allow_get_array = (config_item('allow_get_array') === TRUE);
  85. $this->_enable_xss = (config_item('global_xss_filtering') === TRUE);
  86. $this->_enable_csrf = (config_item('csrf_protection') === TRUE);
  87. global $SEC;
  88. $this->security =& $SEC;
  89. // Do we need the UTF-8 class?
  90. if (UTF8_ENABLED === TRUE)
  91. {
  92. global $UNI;
  93. $this->uni =& $UNI;
  94. }
  95. // Sanitize global arrays
  96. $this->_sanitize_globals();
  97. }
  98. // --------------------------------------------------------------------
  99. /**
  100. * Fetch from array
  101. *
  102. * This is a helper function to retrieve values from global arrays
  103. *
  104. * @access private
  105. * @param array
  106. * @param string
  107. * @param bool
  108. * @return string
  109. */
  110. function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE)
  111. {
  112. if ( ! isset($array[$index]))
  113. {
  114. return FALSE;
  115. }
  116. if ($xss_clean === TRUE)
  117. {
  118. return $this->security->xss_clean($array[$index]);
  119. }
  120. return $array[$index];
  121. }
  122. // --------------------------------------------------------------------
  123. /**
  124. * Fetch an item from the GET array
  125. *
  126. * @access public
  127. * @param string
  128. * @param bool
  129. * @return string
  130. */
  131. function get($index = NULL, $xss_clean = FALSE)
  132. {
  133. // Check if a field has been provided
  134. if ($index === NULL AND ! empty($_GET))
  135. {
  136. $get = array();
  137. // loop through the full _GET array
  138. foreach (array_keys($_GET) as $key)
  139. {
  140. $get[$key] = $this->_fetch_from_array($_GET, $key, $xss_clean);
  141. }
  142. return $get;
  143. }
  144. return $this->_fetch_from_array($_GET, $index, $xss_clean);
  145. }
  146. // --------------------------------------------------------------------
  147. /**
  148. * Fetch an item from the POST array
  149. *
  150. * @access public
  151. * @param string
  152. * @param bool
  153. * @return string
  154. */
  155. function post($index = NULL, $xss_clean = FALSE)
  156. {
  157. // Check if a field has been provided
  158. if ($index === NULL AND ! empty($_POST))
  159. {
  160. $post = array();
  161. // Loop through the full _POST array and return it
  162. foreach (array_keys($_POST) as $key)
  163. {
  164. $post[$key] = $this->_fetch_from_array($_POST, $key, $xss_clean);
  165. }
  166. return $post;
  167. }
  168. return $this->_fetch_from_array($_POST, $index, $xss_clean);
  169. }
  170. // --------------------------------------------------------------------
  171. /**
  172. * Fetch an item from either the GET array or the POST
  173. *
  174. * @access public
  175. * @param string The index key
  176. * @param bool XSS cleaning
  177. * @return string
  178. */
  179. function get_post($index = '', $xss_clean = FALSE)
  180. {
  181. if ( ! isset($_POST[$index]) )
  182. {
  183. return $this->get($index, $xss_clean);
  184. }
  185. else
  186. {
  187. return $this->post($index, $xss_clean);
  188. }
  189. }
  190. // --------------------------------------------------------------------
  191. /**
  192. * Fetch an item from the COOKIE array
  193. *
  194. * @access public
  195. * @param string
  196. * @param bool
  197. * @return string
  198. */
  199. function cookie($index = '', $xss_clean = FALSE)
  200. {
  201. return $this->_fetch_from_array($_COOKIE, $index, $xss_clean);
  202. }
  203. // ------------------------------------------------------------------------
  204. /**
  205. * Set cookie
  206. *
  207. * Accepts six parameter, or you can submit an associative
  208. * array in the first parameter containing all the values.
  209. *
  210. * @access public
  211. * @param mixed
  212. * @param string the value of the cookie
  213. * @param string the number of seconds until expiration
  214. * @param string the cookie domain. Usually: .yourdomain.com
  215. * @param string the cookie path
  216. * @param string the cookie prefix
  217. * @param bool true makes the cookie secure
  218. * @return void
  219. */
  220. function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE)
  221. {
  222. if (is_array($name))
  223. {
  224. // always leave 'name' in last place, as the loop will break otherwise, due to $$item
  225. foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'name') as $item)
  226. {
  227. if (isset($name[$item]))
  228. {
  229. $$item = $name[$item];
  230. }
  231. }
  232. }
  233. if ($prefix == '' AND config_item('cookie_prefix') != '')
  234. {
  235. $prefix = config_item('cookie_prefix');
  236. }
  237. if ($domain == '' AND config_item('cookie_domain') != '')
  238. {
  239. $domain = config_item('cookie_domain');
  240. }
  241. if ($path == '/' AND config_item('cookie_path') != '/')
  242. {
  243. $path = config_item('cookie_path');
  244. }
  245. if ($secure == FALSE AND config_item('cookie_secure') != FALSE)
  246. {
  247. $secure = config_item('cookie_secure');
  248. }
  249. if ( ! is_numeric($expire))
  250. {
  251. $expire = time() - 86500;
  252. }
  253. else
  254. {
  255. $expire = ($expire > 0) ? time() + $expire : 0;
  256. }
  257. setcookie($prefix.$name, $value, $expire, $path, $domain, $secure);
  258. }
  259. // --------------------------------------------------------------------
  260. /**
  261. * Fetch an item from the SERVER array
  262. *
  263. * @access public
  264. * @param string
  265. * @param bool
  266. * @return string
  267. */
  268. function server($index = '', $xss_clean = FALSE)
  269. {
  270. return $this->_fetch_from_array($_SERVER, $index, $xss_clean);
  271. }
  272. // --------------------------------------------------------------------
  273. /**
  274. * Fetch the IP Address
  275. *
  276. * @return string
  277. */
  278. public function ip_address()
  279. {
  280. if ($this->ip_address !== FALSE)
  281. {
  282. return $this->ip_address;
  283. }
  284. $proxy_ips = config_item('proxy_ips');
  285. if ( ! empty($proxy_ips))
  286. {
  287. $proxy_ips = explode(',', str_replace(' ', '', $proxy_ips));
  288. foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP') as $header)
  289. {
  290. if (($spoof = $this->server($header)) !== FALSE)
  291. {
  292. // Some proxies typically list the whole chain of IP
  293. // addresses through which the client has reached us.
  294. // e.g. client_ip, proxy_ip1, proxy_ip2, etc.
  295. if (strpos($spoof, ',') !== FALSE)
  296. {
  297. $spoof = explode(',', $spoof, 2);
  298. $spoof = $spoof[0];
  299. }
  300. if ( ! $this->valid_ip($spoof))
  301. {
  302. $spoof = FALSE;
  303. }
  304. else
  305. {
  306. break;
  307. }
  308. }
  309. }
  310. $this->ip_address = ($spoof !== FALSE && in_array($_SERVER['REMOTE_ADDR'], $proxy_ips, TRUE))
  311. ? $spoof : $_SERVER['REMOTE_ADDR'];
  312. }
  313. else
  314. {
  315. $this->ip_address = $_SERVER['REMOTE_ADDR'];
  316. }
  317. if ( ! $this->valid_ip($this->ip_address))
  318. {
  319. $this->ip_address = '0.0.0.0';
  320. }
  321. return $this->ip_address;
  322. }
  323. // --------------------------------------------------------------------
  324. /**
  325. * Validate IP Address
  326. *
  327. * @access public
  328. * @param string
  329. * @param string ipv4 or ipv6
  330. * @return bool
  331. */
  332. public function valid_ip($ip, $which = '')
  333. {
  334. $which = strtolower($which);
  335. // First check if filter_var is available
  336. if (is_callable('filter_var'))
  337. {
  338. switch ($which) {
  339. case 'ipv4':
  340. $flag = FILTER_FLAG_IPV4;
  341. break;
  342. case 'ipv6':
  343. $flag = FILTER_FLAG_IPV6;
  344. break;
  345. default:
  346. $flag = '';
  347. break;
  348. }
  349. return (bool) filter_var($ip, FILTER_VALIDATE_IP, $flag);
  350. }
  351. if ($which !== 'ipv6' && $which !== 'ipv4')
  352. {
  353. if (strpos($ip, ':') !== FALSE)
  354. {
  355. $which = 'ipv6';
  356. }
  357. elseif (strpos($ip, '.') !== FALSE)
  358. {
  359. $which = 'ipv4';
  360. }
  361. else
  362. {
  363. return FALSE;
  364. }
  365. }
  366. $func = '_valid_'.$which;
  367. return $this->$func($ip);
  368. }
  369. // --------------------------------------------------------------------
  370. /**
  371. * Validate IPv4 Address
  372. *
  373. * Updated version suggested by Geert De Deckere
  374. *
  375. * @access protected
  376. * @param string
  377. * @return bool
  378. */
  379. protected function _valid_ipv4($ip)
  380. {
  381. $ip_segments = explode('.', $ip);
  382. // Always 4 segments needed
  383. if (count($ip_segments) !== 4)
  384. {
  385. return FALSE;
  386. }
  387. // IP can not start with 0
  388. if ($ip_segments[0][0] == '0')
  389. {
  390. return FALSE;
  391. }
  392. // Check each segment
  393. foreach ($ip_segments as $segment)
  394. {
  395. // IP segments must be digits and can not be
  396. // longer than 3 digits or greater then 255
  397. if ($segment == '' OR preg_match("/[^0-9]/", $segment) OR $segment > 255 OR strlen($segment) > 3)
  398. {
  399. return FALSE;
  400. }
  401. }
  402. return TRUE;
  403. }
  404. // --------------------------------------------------------------------
  405. /**
  406. * Validate IPv6 Address
  407. *
  408. * @access protected
  409. * @param string
  410. * @return bool
  411. */
  412. protected function _valid_ipv6($str)
  413. {
  414. // 8 groups, separated by :
  415. // 0-ffff per group
  416. // one set of consecutive 0 groups can be collapsed to ::
  417. $groups = 8;
  418. $collapsed = FALSE;
  419. $chunks = array_filter(
  420. preg_split('/(:{1,2})/', $str, NULL, PREG_SPLIT_DELIM_CAPTURE)
  421. );
  422. // Rule out easy nonsense
  423. if (current($chunks) == ':' OR end($chunks) == ':')
  424. {
  425. return FALSE;
  426. }
  427. // PHP supports IPv4-mapped IPv6 addresses, so we'll expect those as well
  428. if (strpos(end($chunks), '.') !== FALSE)
  429. {
  430. $ipv4 = array_pop($chunks);
  431. if ( ! $this->_valid_ipv4($ipv4))
  432. {
  433. return FALSE;
  434. }
  435. $groups--;
  436. }
  437. while ($seg = array_pop($chunks))
  438. {
  439. if ($seg[0] == ':')
  440. {
  441. if (--$groups == 0)
  442. {
  443. return FALSE; // too many groups
  444. }
  445. if (strlen($seg) > 2)
  446. {
  447. return FALSE; // long separator
  448. }
  449. if ($seg == '::')
  450. {
  451. if ($collapsed)
  452. {
  453. return FALSE; // multiple collapsed
  454. }
  455. $collapsed = TRUE;
  456. }
  457. }
  458. elseif (preg_match("/[^0-9a-f]/i", $seg) OR strlen($seg) > 4)
  459. {
  460. return FALSE; // invalid segment
  461. }
  462. }
  463. return $collapsed OR $groups == 1;
  464. }
  465. // --------------------------------------------------------------------
  466. /**
  467. * User Agent
  468. *
  469. * @access public
  470. * @return string
  471. */
  472. function user_agent()
  473. {
  474. if ($this->user_agent !== FALSE)
  475. {
  476. return $this->user_agent;
  477. }
  478. $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT'];
  479. return $this->user_agent;
  480. }
  481. // --------------------------------------------------------------------
  482. /**
  483. * Sanitize Globals
  484. *
  485. * This function does the following:
  486. *
  487. * Unsets $_GET data (if query strings are not enabled)
  488. *
  489. * Unsets all globals if register_globals is enabled
  490. *
  491. * Standardizes newline characters to \n
  492. *
  493. * @access private
  494. * @return void
  495. */
  496. function _sanitize_globals()
  497. {
  498. // It would be "wrong" to unset any of these GLOBALS.
  499. $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST',
  500. '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA',
  501. 'system_folder', 'application_folder', 'BM', 'EXT',
  502. 'CFG', 'URI', 'RTR', 'OUT', 'IN');
  503. // Unset globals for securiy.
  504. // This is effectively the same as register_globals = off
  505. foreach (array($_GET, $_POST, $_COOKIE) as $global)
  506. {
  507. if ( ! is_array($global))
  508. {
  509. if ( ! in_array($global, $protected))
  510. {
  511. global $$global;
  512. $$global = NULL;
  513. }
  514. }
  515. else
  516. {
  517. foreach ($global as $key => $val)
  518. {
  519. if ( ! in_array($key, $protected))
  520. {
  521. global $$key;
  522. $$key = NULL;
  523. }
  524. }
  525. }
  526. }
  527. // Is $_GET data allowed? If not we'll set the $_GET to an empty array
  528. if ($this->_allow_get_array == FALSE)
  529. {
  530. $_GET = array();
  531. }
  532. else
  533. {
  534. if (is_array($_GET) AND count($_GET) > 0)
  535. {
  536. foreach ($_GET as $key => $val)
  537. {
  538. $_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
  539. }
  540. }
  541. }
  542. // Clean $_POST Data
  543. if (is_array($_POST) AND count($_POST) > 0)
  544. {
  545. foreach ($_POST as $key => $val)
  546. {
  547. $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
  548. }
  549. }
  550. // Clean $_COOKIE Data
  551. if (is_array($_COOKIE) AND count($_COOKIE) > 0)
  552. {
  553. // Also get rid of specially treated cookies that might be set by a server
  554. // or silly application, that are of no use to a CI application anyway
  555. // but that when present will trip our 'Disallowed Key Characters' alarm
  556. // http://www.ietf.org/rfc/rfc2109.txt
  557. // note that the key names below are single quoted strings, and are not PHP variables
  558. unset($_COOKIE['$Version']);
  559. unset($_COOKIE['$Path']);
  560. unset($_COOKIE['$Domain']);
  561. // Work-around for PHP bug #66827 (https://bugs.php.net/bug.php?id=66827)
  562. //
  563. // The session ID sanitizer doesn't check for the value type and blindly does
  564. // an implicit cast to string, which triggers an 'Array to string' E_NOTICE.
  565. $sess_cookie_name = config_item('cookie_prefix').config_item('sess_cookie_name');
  566. if (isset($_COOKIE[$sess_cookie_name]) && ! is_string($_COOKIE[$sess_cookie_name]))
  567. {
  568. unset($_COOKIE[$sess_cookie_name]);
  569. }
  570. foreach ($_COOKIE as $key => $val)
  571. {
  572. // _clean_input_data() has been reported to break encrypted cookies
  573. if ($key === $sess_cookie_name && config_item('sess_encrypt_cookie'))
  574. {
  575. continue;
  576. }
  577. $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
  578. }
  579. }
  580. // Sanitize PHP_SELF
  581. $_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
  582. // CSRF Protection check on HTTP requests
  583. if ($this->_enable_csrf == TRUE && ! $this->is_cli_request())
  584. {
  585. $this->security->csrf_verify();
  586. }
  587. log_message('debug', "Global POST and COOKIE data sanitized");
  588. }
  589. // --------------------------------------------------------------------
  590. /**
  591. * Clean Input Data
  592. *
  593. * This is a helper function. It escapes data and
  594. * standardizes newline characters to \n
  595. *
  596. * @access private
  597. * @param string
  598. * @return string
  599. */
  600. function _clean_input_data($str)
  601. {
  602. if (is_array($str))
  603. {
  604. $new_array = array();
  605. foreach ($str as $key => $val)
  606. {
  607. $new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
  608. }
  609. return $new_array;
  610. }
  611. /* We strip slashes if magic quotes is on to keep things consistent
  612. NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and
  613. it will probably not exist in future versions at all.
  614. */
  615. if ( ! is_php('5.4') && get_magic_quotes_gpc())
  616. {
  617. $str = stripslashes($str);
  618. }
  619. // Clean UTF-8 if supported
  620. if (UTF8_ENABLED === TRUE)
  621. {
  622. $str = $this->uni->clean_string($str);
  623. }
  624. // Remove control characters
  625. $str = remove_invisible_characters($str);
  626. // Should we filter the input data?
  627. if ($this->_enable_xss === TRUE)
  628. {
  629. $str = $this->security->xss_clean($str);
  630. }
  631. // Standardize newlines if needed
  632. if ($this->_standardize_newlines == TRUE)
  633. {
  634. if (strpos($str, "\r") !== FALSE)
  635. {
  636. $str = str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str);
  637. }
  638. }
  639. return $str;
  640. }
  641. // --------------------------------------------------------------------
  642. /**
  643. * Clean Keys
  644. *
  645. * This is a helper function. To prevent malicious users
  646. * from trying to exploit keys we make sure that keys are
  647. * only named with alpha-numeric text and a few other items.
  648. *
  649. * @access private
  650. * @param string
  651. * @return string
  652. */
  653. function _clean_input_keys($str)
  654. {
  655. if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
  656. {
  657. exit('Disallowed Key Characters.');
  658. }
  659. // Clean UTF-8 if supported
  660. if (UTF8_ENABLED === TRUE)
  661. {
  662. $str = $this->uni->clean_string($str);
  663. }
  664. return $str;
  665. }
  666. // --------------------------------------------------------------------
  667. /**
  668. * Request Headers
  669. *
  670. * In Apache, you can simply call apache_request_headers(), however for
  671. * people running other webservers the function is undefined.
  672. *
  673. * @param bool XSS cleaning
  674. *
  675. * @return array
  676. */
  677. public function request_headers($xss_clean = FALSE)
  678. {
  679. // Look at Apache go!
  680. if (function_exists('apache_request_headers'))
  681. {
  682. $headers = apache_request_headers();
  683. }
  684. else
  685. {
  686. $headers['Content-Type'] = (isset($_SERVER['CONTENT_TYPE'])) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE');
  687. foreach ($_SERVER as $key => $val)
  688. {
  689. if (strncmp($key, 'HTTP_', 5) === 0)
  690. {
  691. $headers[substr($key, 5)] = $this->_fetch_from_array($_SERVER, $key, $xss_clean);
  692. }
  693. }
  694. }
  695. // take SOME_HEADER and turn it into Some-Header
  696. foreach ($headers as $key => $val)
  697. {
  698. $key = str_replace('_', ' ', strtolower($key));
  699. $key = str_replace(' ', '-', ucwords($key));
  700. $this->headers[$key] = $val;
  701. }
  702. return $this->headers;
  703. }
  704. // --------------------------------------------------------------------
  705. /**
  706. * Get Request Header
  707. *
  708. * Returns the value of a single member of the headers class member
  709. *
  710. * @param string array key for $this->headers
  711. * @param boolean XSS Clean or not
  712. * @return mixed FALSE on failure, string on success
  713. */
  714. public function get_request_header($index, $xss_clean = FALSE)
  715. {
  716. if (empty($this->headers))
  717. {
  718. $this->request_headers();
  719. }
  720. if ( ! isset($this->headers[$index]))
  721. {
  722. return FALSE;
  723. }
  724. if ($xss_clean === TRUE)
  725. {
  726. return $this->security->xss_clean($this->headers[$index]);
  727. }
  728. return $this->headers[$index];
  729. }
  730. // --------------------------------------------------------------------
  731. /**
  732. * Is ajax Request?
  733. *
  734. * Test to see if a request contains the HTTP_X_REQUESTED_WITH header
  735. *
  736. * @return boolean
  737. */
  738. public function is_ajax_request()
  739. {
  740. return ($this->server('HTTP_X_REQUESTED_WITH') === 'XMLHttpRequest');
  741. }
  742. // --------------------------------------------------------------------
  743. /**
  744. * Is cli Request?
  745. *
  746. * Test to see if a request was made from the command line
  747. *
  748. * @return bool
  749. */
  750. public function is_cli_request()
  751. {
  752. return (php_sapi_name() === 'cli' OR defined('STDIN'));
  753. }
  754. }
  755. /* End of file Input.php */
  756. /* Location: ./system/core/Input.php */