PHP - Ip

 
Vista:

Ip

Publicado por eriotza (30 intervenciones) el 23/09/2007 09:40:49
Estoy intentando meter las ip de los usuarios en las bbdd, pongo el campo tipo varchar pero solo me aparecen las dos primeras cifras (antes del primer punto).
Saco la Ip haciendo $_SERVER['REMOTE_ADDR'] y funciona porque lo he comprobado mediante un echo $_SERVER['REMOTE_ADDR'] y salen las cifras. Después lo inserto mediante un formulario y solo aparecen las dos primeras cifras de la Ip en la BBDD.
¿Alguien podría decirme como puedo hacerlo correctamente para que me salgan todas las cifras?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Ip

Publicado por Nicolás (154 intervenciones) el 23/09/2007 16:27:47
Ya habíamos visto algo de esto... no? Como había dicho Diego Romero, revisa que la longitud del campo en la tabla sea lo suficientemente grande como para almacenar una ip. Si no es este el problema, copia parte de tu código así será un poco mas fácil ayudarte.
Suerte
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Ip

Publicado por eriotza (30 intervenciones) el 23/09/2007 19:10:49
Ya amplie la longitud de campo a 30 y no sirvio.
El codigo:

<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "registro")) {
$insertSQL = sprintf("INSERT INTO erabiltzaile (nombre, apellido, ip, ac_key) VALUES (%s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['nombre'], "text"),
GetSQLValueString($HTTP_POST_VARS['apellido'], "text"),
GetSQLValueString($HTTP_POST_VARS['ip'], "int"),
GetSQLValueString($HTTP_POST_VARS['ac_key'], "int"));

mysql_select_db($database_conectar, $conectar);
$Result1 = mysql_query($insertSQL, $conectar) or die(mysql_error());

}
?>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Ip

Publicado por Diego Romero (1450 intervenciones) el 23/09/2007 22:55:10
Acá está el problema:

GetSQLValueString($HTTP_POST_VARS['ip'], "int"),

Debería ser:

GetSQLValueString($HTTP_POST_VARS['ip'], "text"),

Una IP tal como la devuelve $_SERVER["REMOTE_ADDR"] no coincide con el tipo int, sino con text.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Ip

Publicado por eriotza (30 intervenciones) el 24/09/2007 15:35:42
Muchas gracias me ha funcionado

Un saludo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar