Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/04/2014, 10:57
KalSmith
 
Fecha de Ingreso: marzo-2014
Mensajes: 56
Antigüedad: 10 años, 1 mes
Puntos: 1
Como Agregar Seguridad en formulario?

Junto con saludar, quisiera nuevamente molestarlos, estoy realizando mi sitio .en php y mysql, con dreamweaver. y el problema es que estoy agregando un formulario. y a este quisiera agregarle seguridad.

Código PHP:
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$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 tblcontacto (StrNombre, StrMail, intTel) VALUES (%s, %s, %s)",
                       
GetSQLValueString($_POST[''], "text"),
                       
GetSQLValueString($_POST['StrMail'], "text"),
                       
GetSQLValueString($_POST['intTel'], "text"));

  
mysql_select_db($database_con_pro$con_pro);
  
$Result1 mysql_query($insertSQL$con_pro) or die(mysql_error());
}
?> 

Código PHP:
<div id="mainContent">
      <form action="<?php echo $editFormAction?>" method="post" id="form1">
        <table>
          <tr valign="baseline">
            <td align="right">Nombre:</td>
            <td><span id="sprytextfield1">
              <input type="text" name="StrNombre" value="" size="32" />
            <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
          </tr>
          <tr valign="baseline">
            <td align="right">Mail:</td>
            <td><span id="sprytextfield2">
            <input type="text" name="StrMail" value="" size="32" />
            <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
          </tr>
          <tr valign="baseline">
            <td align="right">Telefono:</td>
            <td><span id="sprytextfield3">
              <input type="text" name="intTel" value="" size="32" />
            <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
          </tr>
          <tr valign="baseline">
            <td align="right">&nbsp;</td>
            <td><input type="submit" value="Enviar" /></td>
          </tr>
        </table>
        <input type="hidden" name="MM_insert" value="form1" />
      </form>
La idea que en ningún campo puedan meter caracteres como < > / \ = $ o los que mas adelante pueda considerar como peligroso, he estado leyendo, pero no entiendo o no se donde tengo que insertar ese código.

Se agradece su ayuda =D

A algun mod, favor cambiar nombre de tema a Seguridad en formulario.

Gracais y disculpen.

Gracias !!