security_helper.php

Go to the documentation of this file.
00001 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002 /**
00003  * CodeIgniter
00004  *
00005  * An open source application development framework for PHP 4.3.2 or newer
00006  *
00007  * @package             CodeIgniter
00008  * @author              ExpressionEngine Dev Team
00009  * @copyright   Copyright (c) 2006, EllisLab, Inc.
00010  * @license             http://codeigniter.com/user_guide/license.html
00011  * @link                http://codeigniter.com
00012  * @since               Version 1.0
00013  * @filesource
00014  */
00015 
00016 // ------------------------------------------------------------------------
00017 
00018 /**
00019  * CodeIgniter Security Helpers
00020  *
00021  * @package             CodeIgniter
00022  * @subpackage  Helpers
00023  * @category    Helpers
00024  * @author              ExpressionEngine Dev Team
00025  * @link                http://codeigniter.com/user_guide/helpers/security_helper.html
00026  */
00027 
00028 // ------------------------------------------------------------------------
00029 
00030 /**
00031  * XSS Filtering
00032  *
00033  * @access      public
00034  * @param       string
00035  * @param       string  the character set of your data
00036  * @return      string
00037  */     
00038 if ( ! function_exists('xss_clean'))
00039 {
00040         function xss_clean($str, $charset = 'ISO-8859-1')
00041         {
00042                 $CI =& get_instance();
00043                 return $CI->input->xss_clean($str, $charset);
00044         }
00045 }
00046 
00047 // --------------------------------------------------------------------
00048 
00049 /**
00050  * Hash encode a string
00051  *
00052  * @access      public
00053  * @param       string
00054  * @return      string
00055  */     
00056 if ( ! function_exists('dohash'))
00057 {       
00058         function dohash($str, $type = 'sha1')
00059         {
00060                 if ($type == 'sha1')
00061                 {
00062                         if ( ! function_exists('sha1'))
00063                         {
00064                                 if ( ! function_exists('mhash'))
00065                                 {       
00066                                         require_once(BASEPATH.'libraries/Sha1'.EXT);
00067                                         $SH = new CI_SHA;
00068                                         return $SH->generate($str);
00069                                 }
00070                                 else
00071                                 {
00072                                         return bin2hex(mhash(MHASH_SHA1, $str));
00073                                 }
00074                         }
00075                         else
00076                         {
00077                                 return sha1($str);
00078                         }       
00079                 }
00080                 else
00081                 {
00082                         return md5($str);
00083                 }
00084         }
00085 }
00086         
00087 // ------------------------------------------------------------------------
00088 
00089 /**
00090  * Strip Image Tags
00091  *
00092  * @access      public
00093  * @param       string
00094  * @return      string
00095  */     
00096 if ( ! function_exists('strip_image_tags'))
00097 {
00098         function strip_image_tags($str)
00099         {
00100                 $str = preg_replace("#<img\s+.*?src\s*=\s*[\"'](.+?)[\"'].*?>#", "\\1", $str);
00101                 $str = preg_replace("#<img\s+.*?src\s*=\s*(.+?).*?>#", "\\1", $str);
00102                         
00103                 return $str;
00104         }
00105 }
00106         
00107 // ------------------------------------------------------------------------
00108 
00109 /**
00110  * Convert PHP tags to entities
00111  *
00112  * @access      public
00113  * @param       string
00114  * @return      string
00115  */     
00116 if ( ! function_exists('encode_php_tags'))
00117 {
00118         function encode_php_tags($str)
00119         {
00120                 return str_replace(array('<?php', '<?PHP', '<?', '?>'),  array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
00121         }
00122 }
00123 
00124 
00125 /* End of file security_helper.php */
00126 /* Location: ./system/helpers/security_helper.php */