-3

I want to log the execution of a php file on a .txt file.
I want the file to look like this with serial number:

1, (time)
2, (time)
3, (time)
. . . . .
. . . . .

where (time) is the time of execution of the php file.

How to add the serial number to each line and how to put each entry on next line?

$today = date("Y-m-d H:i:s"); 
$file = fopen("log.txt","a+");
fwrite($file,$today);
fclose($file);
Saif
  • 2,530
  • 3
  • 27
  • 45

2 Answers2

2
  1. Create your file on your server/computer, in the same place where you put your PHP file. Fore this example we'll call it "log.txt"
  2. Do what you have to do to make the file writable. For this example, you can just right-click it in Filezilla and choose "permissions", then change it to 777, or Google how to use chmod.
  3. In your script, paste the following code:

    $fh = fopen("log.txt","a+");

    fwrite($fh, date("Y-m-d g:i a")."\r\n");

    fclose($fh);

http://php.net/manual/en/function.fopen.php

http://php.net/manual/en/function.fwrite.php

I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
0

Since you did not provide any code, here is a hint on how you can do it:

File_Put_Contents('../file path/yourlog.txt',$yourfilecontent, FILE_APPEND);
Luthando Ntsekwa
  • 4,192
  • 6
  • 23
  • 52