Foros del Web » Programando para Internet » PHP »

Script para evitar SQL injection

Estas en el tema de Script para evitar SQL injection en el foro de PHP en Foros del Web. Saludos Navegando en internet encontre este codigo modificado de Dreamweaver para la funcion GetSQLValueString muy usada por DW Código PHP: <?php   if (! function_exists ( "GetSQLValueString" ...
  #1 (permalink)  
Antiguo 16/10/2008, 19:45
 
Fecha de Ingreso: mayo-2007
Mensajes: 27
Antigüedad: 16 años, 11 meses
Puntos: 0
Pregunta Script para evitar SQL injection

Saludos

Navegando en internet encontre este codigo modificado de Dreamweaver para la funcion GetSQLValueString muy usada por DW

Código PHP:
<?php  if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"text2":
      
$theValue = ($theValue != "") ? "" $theValue "" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      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;
}
}
?>
Creen que este completo y correcto? y cubra la mayoria de tipo de datos que pueden pasar como variables en mysql. No se mucho de php y quiero implementarlo en mi web
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:12.