Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/05/2008, 08:39
Ruben_C
 
Fecha de Ingreso: febrero-2006
Mensajes: 217
Antigüedad: 18 años, 2 meses
Puntos: 0
Exclamación ¿como detener inyeccion sql?

Hola a todos nuevamente, sigo aprendiendo en esto de la web y ahora me interesa detener lo que supongo es una inyeccion sql. Esto es lo que me insertan en el form:

Código HTML:
Good site. Thanks.
<A href='http://jamespostell.c0n.us/naruto1193.html'>naruto</A> 
y mucho mas.

Yo suponia que la primera parte de este script era para eliminar ese tipo de cosas (lo hace dreamweaver automaticamente), pero parece que no:

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 
"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;
  }
  return 
$theValue;
}
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO post (nombre, comentario) VALUES (%s, %s)",
                       
GetSQLValueString($_POST['nombre'], "text"),
                       
GetSQLValueString($_POST['comentario'], "text"));

  
mysql_select_db($database_post$post);
  
$Result1 mysql_query($insertSQL$post) or die(mysql_error());

  
$insertGoTo "post.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}

mysql_select_db($database_post$post);
$query_post "SELECT * FROM post";
$post mysql_query($query_post$post) or die(mysql_error());
$row_post mysql_fetch_assoc($post);
$totalRows_post mysql_num_rows($post);
?>
Como hago para que no me ingresen mas estos datos en el form?

Última edición por Ruben_C; 05/05/2008 a las 08:48