0

Can anyone tell me how can I get the last result in the first line of a PHP return rather than having the last result in the last line. Here's my code:

<?php
$ip_get = date("Y/m/d") ." ". date("h:i:sa") . "    " . getRealIpAddr() . " " . 
PHP_EOL ;
$filename1 = 'iplogsget.csv';
file_put_contents($filename1, $ip_get , FILE_APPEND);
?>

At the moment, it outputs something like:

2021/07/22 12:51:58pm XXX.XXX.XXX.XXX
2021/07/22 12:55:58pm XXX.XXX.XXX.XXX

And I would like this kind of output instead:

2021/07/22 12:55:58pm XXX.XXX.XXX.XXX
2021/07/22 12:51:58pm XXX.XXX.XXX.XXX
Aissa Laribi
  • 97
  • 1
  • 1
  • 8
  • 2
    Does https://stackoverflow.com/questions/3332262/how-do-i-prepend-file-to-beginning/3332403 help? – Nico Haase Jul 22 '21 at 12:30
  • @Nico Haase Thanks it helped me perfectly I've replaced $prepend ="prepend me please" by my variable $ip_get and it works – Aissa Laribi Jul 22 '21 at 13:10
  • @AndreaOlivato Thanks it helped me perfectly I've replaced $prepend ="prepend me please" by my variable $ip_get and it works – Aissa Laribi Jul 22 '21 at 13:10

1 Answers1

0
<?php
$ip_get = date("Y/m/d") ." ". date("h:i:sa") . "    " . getRealIpAddr() . 
" " . PHP_EOL ;
$filename1 = 'iplogsget.csv';
$prepend = $ip_get;
$fileContents = file_get_contents($filename1);

file_put_contents($filename1, $prepend . $fileContents);
?>
Aissa Laribi
  • 97
  • 1
  • 1
  • 8