Ver Mensaje Individual
  #3 (permalink)  
Antiguo 01/04/2009, 11:05
Avatar de farra
farra
 
Fecha de Ingreso: marzo-2008
Ubicación: Aqui estoy
Mensajes: 574
Antigüedad: 17 años
Puntos: 20
Respuesta: Se puede agregar algo mas en cuestion de seguridad?

es opcionar pero podrias validar el tipo de dato y la longitud...
Código PHP:
if (!function_exists("seguridad")) {
function 
seguridad($theValue$theType$theDefinedValue ""$theNotDefinedValue ""$tamanomax
{

  
// longitud del texto
  
$theValue=substr($theValue0$tamanomax);

  
// contra inyeccion sql
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 
// tipo de dato
  
switch ($theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"text2":
      
$theValue = ($theValue != "") ? "" $theValue "" "";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"intonulo":
      
$theValue = ($theValue != "") ? intval($theValue) : "";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
    case 
"like":
      
$theValue = ($theValue != "") ? "'%" $theValue "%'" "NULL";
      break;
    case 
"likedespues":
      
$theValue = ($theValue != "") ? "'" $theValue "%'" "NULL";
      break;
    case 
"likeantes":
      
$theValue = ($theValue != "") ? "'%" $theValue "'" "NULL";
      break;
  }

  return 
$theValue;
}

Como usar:
Código PHP:
<?php
// variable, tipo de dato, longitud maxima
$dato=seguridad($_POST['variable'],"int",10);
?>
__________________
Firma:
Es mas dificil para el mono entender que el hombre desciende de el....

PD: Siempre doy karma al que me da una buena respuesta... ;0)

Última edición por farra; 02/04/2009 a las 07:43