Ver Mensaje Individual
  #2 (permalink)  
Antiguo 30/09/2010, 20:01
Avatar de abimaelrc
abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: Guardar IPs en un .txt

Trata esta forma sencilla
Código PHP:
Ver original
  1. <?php
  2. $file = 'comments.txt';
  3. $reverse = true;
  4.  
  5. if(!empty($_POST['token']) && !empty($_SESSION['token']) && $_SESSION['token'] != $_POST['token']){
  6.     $txt = array();
  7.     foreach($_POST as $key => $val){ $txt[$key] = $val; }
  8.     $txt['ip'] = $_SERVER['REMOTE_ADDR'];
  9.     file_put_contents($file, serialize($txt) . PHP_EOL, FILE_APPEND);
  10. }
  11. $_SESSION['token'] = !empty($_POST['token']) ? $_POST['token'] : mt_rand();
  12. ?>
  13.  
  14. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  15.     <input type="hidden" name="token" value="<?php echo mt_rand(); ?>" />
  16.     <input type="text" name="Name" /><br />
  17.     <textarea name="comment" cols="30" rows="5"></textarea><br />
  18.     <input type="submit" />
  19. </form>
  20.  
  21. <?php
  22. if(file_exists($file)){
  23.     $comments = $reverse ? array_reverse(file($file)) : file($file);
  24.     foreach($comments as $val){
  25.         $data = unserialize($val);
  26. ?>
  27.     <fieldset>
  28.         <legend><?php echo $data['Name'] . ' ' . $data['ip']; ?></legend>
  29.         <?php echo $data['comment']; ?>
  30.     </fieldset>
  31. <?php
  32.     }
  33. }
  34. ?>
Esto es de comentarios pero para que veas una forma de hacerlo bien sencilla
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos