security_helper.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. * CodeIgniter Security Helpers
  19. *
  20. * @package CodeIgniter
  21. * @subpackage Helpers
  22. * @category Helpers
  23. * @author EllisLab Dev Team
  24. * @link http://codeigniter.com/user_guide/helpers/security_helper.html
  25. */
  26. // ------------------------------------------------------------------------
  27. /**
  28. * XSS Filtering
  29. *
  30. * @access public
  31. * @param string
  32. * @param bool whether or not the content is an image file
  33. * @return string
  34. */
  35. if ( ! function_exists('xss_clean'))
  36. {
  37. function xss_clean($str, $is_image = FALSE)
  38. {
  39. $CI =& get_instance();
  40. return $CI->security->xss_clean($str, $is_image);
  41. }
  42. }
  43. // ------------------------------------------------------------------------
  44. /**
  45. * Sanitize Filename
  46. *
  47. * @access public
  48. * @param string
  49. * @return string
  50. */
  51. if ( ! function_exists('sanitize_filename'))
  52. {
  53. function sanitize_filename($filename)
  54. {
  55. $CI =& get_instance();
  56. return $CI->security->sanitize_filename($filename);
  57. }
  58. }
  59. // --------------------------------------------------------------------
  60. /**
  61. * Hash encode a string
  62. *
  63. * @access public
  64. * @param string
  65. * @return string
  66. */
  67. if ( ! function_exists('do_hash'))
  68. {
  69. function do_hash($str, $type = 'sha1')
  70. {
  71. if ($type == 'sha1')
  72. {
  73. return sha1($str);
  74. }
  75. else
  76. {
  77. return md5($str);
  78. }
  79. }
  80. }
  81. // ------------------------------------------------------------------------
  82. /**
  83. * Strip Image Tags
  84. *
  85. * @access public
  86. * @param string
  87. * @return string
  88. */
  89. if ( ! function_exists('strip_image_tags'))
  90. {
  91. function strip_image_tags($str)
  92. {
  93. $str = preg_replace("#<img\s+.*?src\s*=\s*[\"'](.+?)[\"'].*?\>#", "\\1", $str);
  94. $str = preg_replace("#<img\s+.*?src\s*=\s*(.+?).*?\>#", "\\1", $str);
  95. return $str;
  96. }
  97. }
  98. // ------------------------------------------------------------------------
  99. /**
  100. * Convert PHP tags to entities
  101. *
  102. * @access public
  103. * @param string
  104. * @return string
  105. */
  106. if ( ! function_exists('encode_php_tags'))
  107. {
  108. function encode_php_tags($str)
  109. {
  110. return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
  111. }
  112. }
  113. /* End of file security_helper.php */
  114. /* Location: ./system/helpers/security_helper.php */