Obtener ip

  • Autor Autor mxmex
  • Fecha de inicio Fecha de inicio
M

mxmex

Épsilon
Tengo este formulario y necesito agregar alguna linea que me detecte la IP del visitante y me la envie junto al formulario.
Que linea podria insertar en que parte del codigo.
Agradezco ayuda.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table width="594" border="0" align="center">
<tr>
<td><p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="156">&nbsp;</td>
<td width="428"><?php
/*Formulario de contacto HTML5, PHP Y Bootstraps
Creado por: Render2web
Version: 1.1*/

//Comprobamos que se haya presionado el boton enviar
if(isset($_POST['enviar'])){
//Guardamos en variables los datos enviados
$nombre = $_POST['nombre'];
$email = $_POST['email'];
$telefono = $_POST['telefono'];
$pais = $_POST['pais'];
$estado = $_POST['estado'];
$ciudad = $_POST['ciudad'];
$emailsec = $_POST['emailsec'];
$mensaje = $_POST['mensaje'];

///Validamos del lado del servidor que el nombre y el email no estén vacios
if($nombre == ''){
echo "Informacion";
}
else if($email == ''){
echo "info@lastapatias.com.mx";
}else{
$para = "info@lastapatias.com.mx";//Email al que se enviará
$asunto = "Contacto por Informacion";//Puedes cambiar el asunto del mensaje desde aqui
//Este sería el cuerpo del mensaje
$mensaje = "
<table border='0' cellspacing='3' cellpadding='2'>
<tr>
<td width='30%' align='left' bgcolor='#f0efef'><strong>Nombre:</strong></td>
<td width='80%' align='left'>$nombre</td>
</tr>
<tr>
<td align='left' bgcolor='#f0efef'><strong>E-mail:</strong></td>
<td align='left'>$email</td>
</tr>
<tr>
<td width='30%' align='left' bgcolor='#f0efef'><strong>Teléfono:</strong></td>
<td width='70%' align='left'>$telefono</td>
</tr>
<tr>
<td width='30%' align='left' bgcolor='#f0efef'><strong>Pais:</strong></td>
<td width='70%' align='left'>$pais</td>
</tr>
<tr>
<td width='30%' align='left' bgcolor='#f0efef'><strong>Estado:</strong></td>
<td width='70%' align='left'>$estado</td>
</tr>
<tr>
<td width='30%' align='left' bgcolor='#f0efef'><strong>Ciudad:</strong></td>
<td width='70%' align='left'>$ciudad</td>
</tr>
<tr>
<td width='30%' align='left' bgcolor='#f0efef'><strong>Email Secundario:</strong></td>
<td width='70%' align='left'>$emailsec</td>
</tr>
<tr>
<td align='left' bgcolor='#f0efef'><strong>Comentario:</strong></td>
<td align='left'>$mensaje</td>
</tr>
</table>
";


$link = mysql_connect("localhost","lastapat_usero","contra seña");


mysql_select_db("lastapat_user",$link);


mysql_query("INSERT INTO usuarios (nombre,email,telefono,pais,estado,ciudad,emailsec ,mensaje) VALUES ('".mysql_real_escape_string($_POST['nombre'])."','".mysql_real_escape_string($_POST['email'])."','".mysql_real_escape_string($_POST['telefono'])."','".mysql_real_escape_string($_POST['pais'])."','".mysql_real_escape_string($_POST['estado'])."','".mysql_real_escape_string($_POST['ciudad'])."','".mysql_real_escape_string($_POST['emailsec'])."','".mysql_real_escape_string($_POST['mensaje'])."')",$link);

//Cabeceras del correo
$headers = "From: $nombre <$email>\r\n"; //Quien envia?
$headers .= "X-Mailer: PHP5\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; //

//Comprobamos que los datos enviados a la función MAIL de PHP estén bien y si es correcto enviamos
if(@mail($para, $asunto, $mensaje, $headers)){
echo "Su mensaje se ha enviado correctamente";
echo "<br />";
echo '<a href="../index.html">Regresar a la Pagina Principal</a>';
}else{
echo "Hubo un error en el envío inténtelo más tarde";
}
}
}
?></td>
</tr>
</table>
</body>
</html>
 
Codigo:

Insertar CODE, HTML o PHP:
<?php 
echo "Tu dirección IP es: {$_SERVER['REMOTE_ADDR']}";
?>

Resultado:

Tu dirección IP es: 200.121.192.3
 
Entiendo puse el codigo pero solo lo muestra nada mas.
Como podria hacer que ese codigo me llegue junto con el formulario ?
Muchas gracias por tu ayuda [MENTION=121546]RaulOrCase[/MENTION]
 
Entiendo puse el codigo pero solo lo muestra nada mas.
Como podria hacer que ese codigo me llegue junto con el formulario ?
Muchas gracias por tu ayuda [MENTION=121546]RaulOrCase[/MENTION]

agregalo a la variable mensaje...
 
No tengo ni idea, se supone que mensaje solo va el mensaje.
no se como agragarlo.
disculpas [MENTION=9679]cicklow[/MENTION]
 
No tengo ni idea, se supone que mensaje solo va el mensaje.
no se como agragarlo.
disculpas [MENTION=9679]cicklow[/MENTION]

-.-'...
PHP:
$mensaje = "
<table border='0' cellspacing='3' cellpadding='2'>
<tr>
<td width='30%' align='left' bgcolor='#f0efef'><strong>Nombre:</strong></td>
<td width='80%' align='left'>$nombre</td>
</tr>
<tr>
<td align='left' bgcolor='#f0efef'><strong>E-mail:</strong></td>
<td align='left'>$email</td>
</tr>
<tr>
<td width='30%' align='left' bgcolor='#f0efef'><strong>Teléfono:</strong></td>
<td width='70%' align='left'>$telefono</td>
</tr>
<tr>
<td width='30%' align='left' bgcolor='#f0efef'><strong>Pais:</strong></td>
<td width='70%' align='left'>$pais</td>
</tr>
<tr>
<td width='30%' align='left' bgcolor='#f0efef'><strong>Estado:</strong></td>
<td width='70%' align='left'>$estado</td>
</tr>
<tr>
<td width='30%' align='left' bgcolor='#f0efef'><strong>Ciudad:</strong></td>
<td width='70%' align='left'>$ciudad</td>
</tr>
<tr>
<td width='30%' align='left' bgcolor='#f0efef'><strong>Email Secundario:</strong></td>
<td width='70%' align='left'>$emailsec</td>
</tr>
<tr>
<td align='left' bgcolor='#f0efef'><strong>Comentario:</strong></td>
<td align='left'>$mensaje</td>
</tr>
<tr>
<td align='left' bgcolor='#f0efef'><strong>IP:</strong></td>
<td align='left'>".$_SERVER['REMOTE_ADDR']."</td>
</tr>
</table>
";
 
PHP:
<td align='left'>".$_SERVER['REMOTE_ADDR']."</td>

Protip: puedes hacer esto para no tener que concatenar la variable...

PHP:
<td align='left'>$_SERVER[REMOTE_ADDR]</td>

Nota que no tiene las comillas simples la variable $_SERVER :encouragement:
 
Saludos solo tienes que colocar un:
echo "IP: " . $_SERVER['REMOTE_ADDR'];
Y si esta tras un proxy:

if( isset($_SERVER['HTTP_X_FORWARDED_FOR']) &&
$_SERVER['HTTP_X_FORWARDED_FOR'] != '' )
{
echo "IP: " . $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
echo "IP: " . $_SERVER['REMOTE_ADDR'];
 
Atrás
Arriba