Ver Mensaje Individual
  #8 (permalink)  
Antiguo 30/09/2010, 21:31
kenproxd
 
Fecha de Ingreso: agosto-2009
Mensajes: 349
Antigüedad: 14 años, 9 meses
Puntos: 8
Respuesta: Guardar IPs en un .txt

Creo que ya lo entendi :)

Código PHP:
<?php
session_start
();
$file 'comments.txt';
$reverse true;
$noIpInFile true;
$getComments '';
 
if(!empty(
$_POST['token']) && !empty($_SESSION['token']) && $_SESSION['token'] != $_POST['token']){
    
$txt = array();
    foreach(
$_POST as $key => $val){ $txt[$key] = $val; }
    
$txt['ip'] = $_SERVER['REMOTE_ADDR'];
    
file_put_contents($fileserialize($txt) . PHP_EOLFILE_APPEND);
}
$_SESSION['token'] = !empty($_POST['token']) ? $_POST['token'] : mt_rand();

if(
file_exists($file)){
    
$comments $reverse array_reverse(file($file)) : file($file);
    foreach(
$comments as $val){
        
$data unserialize($val);
        if(
$data['ip'] == $_SERVER['SERVER_ADDR']){ $noIpInFile false; }
        
$getComments .= '//AQUI LO QUE SE MUESTRA SI LA IP ESTA EN EL ARCHIVO .TXT';
    }
}
if(
$noIpInFile){
?>
//AQUI LO QUE SE MUESTRA SI LA IP NO ESTA EN EL ARCHIVO .TXT
<?php 
}
echo 
$getComments;
?>
Agradeceria que me confirmen si estoy en lo correcto :)