Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/04/2010, 11:56
etisdemian
 
Fecha de Ingreso: octubre-2009
Mensajes: 357
Antigüedad: 14 años, 6 meses
Puntos: 1
codigo de seguridad

hola muchachos he encontrado por ahi este codigo
que me dicen?
es efectivo?
se aplica de entrada o salida?


ahi va

Código PHP:
Ver original
  1. <?php
  2.  
  3. function h($string, $esc_type = 'htmlall')
  4. {
  5.     switch ($esc_type) {
  6.         case 'css':
  7.             $string = str_replace(array('<', '>', '\\'), array('&lt;', '&gt;', '/'), $string);
  8.             // get rid of various versions of javascript
  9.             $string = preg_replace(
  10.                     '/j\s*[\\\]*\s*a\s*[\\\]*\s*v\s*[\\\]*\s*a\s*[\\\]*\s*s\s*[\\\]*\s*c\s*[\\\]*\s*r\s*[\\\]*\s*i\s*[\\\]*\s*p\s*[\\\]*\s*t\s*[\\\]*\s*:/i',
  11.                     'blocked', $string);
  12.             $string = preg_replace(
  13.                     '/@\s*[\\\]*\s*i\s*[\\\]*\s*m\s*[\\\]*\s*p\s*[\\\]*\s*o\s*[\\\]*\s*r\s*[\\\]*\s*t/i',
  14.                     'blocked', $string);
  15.             $string = preg_replace(
  16.                     '/e\s*[\\\]*\s*x\s*[\\\]*\s*p\s*[\\\]*\s*r\s*[\\\]*\s*e\s*[\\\]*\s*s\s*[\\\]*\s*s\s*[\\\]*\s*i\s*[\\\]*\s*o\s*[\\\]*\s*n\s*[\\\]*\s*/i',
  17.                     'blocked', $string);
  18.             $string = preg_replace('/b\s*[\\\]*\s*i\s*[\\\]*\s*n\s*[\\\]*\s*d\s*[\\\]*\s*i\s*[\\\]*\s*n\s*[\\\]*\s*g:/i', 'blocked', $string);
  19.                 return $string;
  20.  
  21.         case 'html':
  22.             //return htmlspecialchars($string, ENT_NOQUOTES);
  23.             return str_replace(array('<', '>'), array('&lt;' , '&gt;'), $string);
  24.  
  25.         case 'htmlall':
  26.             return htmlentities($string, ENT_QUOTES);
  27.         case 'url':
  28.             return rawurlencode($string);
  29.         case 'query':
  30.             return urlencode($string);
  31.  
  32.         case 'quotes':
  33.             // escape unescaped single quotes
  34.             return preg_replace("%(?<!\\\\)'%", "\\'", $string);
  35.  
  36.         case 'hex':
  37.             // escape every character into hex
  38.             $s_return = '';
  39.             for ($x=0; $x < strlen($string); $x++) {
  40.                 $s_return .= '%' . bin2hex($string[$x]);
  41.             }
  42.             return $s_return;
  43.  
  44.         case 'hexentity':
  45.             $s_return = '';
  46.             for ($x=0; $x < strlen($string); $x++) {
  47.                 $s_return .= '&#x' . bin2hex($string[$x]) . ';';
  48.             }
  49.             return $s_return;
  50.  
  51.         case 'decentity':
  52.             $s_return = '';
  53.             for ($x=0; $x < strlen($string); $x++) {
  54.                 $s_return .= '&#' . ord($string[$x]) . ';';
  55.             }
  56.             return $s_return;
  57.  
  58.         case 'javascript':
  59.             // escape quotes and backslashes, newlines, etc.
  60.             return strtr($string, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/'));
  61.  
  62.         case 'mail':
  63.             // safe way to display e-mail address on a web page
  64.             return str_replace(array('@', '.'),array(' [AT] ', ' [DOT] '), $string);
  65.  
  66.         case 'nonstd':
  67.             // escape non-standard chars, such as ms document quotes
  68.             $_res = '';
  69.             for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++) {
  70.                 $_ord = ord($string{$_i});
  71.                 // non-standard char, escape it
  72.                 if($_ord >= 126){
  73.                     $_res .= '&#' . $_ord . ';';
  74.                 } else {
  75.                     $_res .= $string{$_i};
  76.                 }
  77.             }
  78.                return $_res;
  79.  
  80.         default:
  81.             return $string;
  82.     }
  83. }
  84.    
  85. ?>