I'm trying to make a text file with some information (Date and IP List).
This is a PHP code for a new file:
//File
$History = history.txt";
//Date
$Today = date("d", time());
//New Data
$Data = Array("TIME" => $Today, "HISTORY" => Array(get_ip()));
//Write to text File
$objData = serialize($Data);
$fp = fopen($History, "w");
fwrite($fp, $objData);
fclose($fp);
Result:
Array (
[TIME] => 19
[HISTORY] => Array ( [0] => 127.0.0.1 )
)
After that, i need to add every new IP to the HISTORY. i wrote this part:
//Get Old Data
$FileRead = unserialize(file_get_contents($History));
if($FileRead[TIME] = $Today){
//ADD NEW IP IN HISTORY PART
}
problem is, i don't know how i can add a new IP in my old file HISTORY array. i need to add new IP's and getting result like this:
Array (
[TIME] => 19
[HISTORY] => Array (
[0] => 127.0.0.1
[1] => 127.12.0.2
[2] => 127.192.0.1
[3] => 127.168.1.5
[4] => ...
)
)
how i can do that with serialize function?