Ver Mensaje Individual
  #7 (permalink)  
Antiguo 30/09/2010, 21:08
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

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