• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

create a "daily" text file and append data to it all day

Hi

I want to log certain things a user does on my site to a dedicated "daily" file, appending to it all day, then creating a new one if its a new date and so on.

Idea file name YYYYMMDD.txt

Could anyone assist with the full code to do this please?

Regards
Neil
0
Neil Thompson
Asked:
Neil Thompson
  • 2
  • 2
1 Solution
 
Julian HansenCommented:
$filename = date('Ymd') . '.txt';

Add to file with append option
example

file_put_contents($filename, $data, FILE_APPEND);

Where $data holds the text you want to write to the file - you can also use fwrite

This way filename will auto roll over to the next day
0
 
Ray PaseurCommented:
In case you want to do any "data mining" or look for trends in the data you might want to use a data base table instead.

Your table definition would consist of a DATETIME column and a column (or perhaps a few columns) to contain the "certain things."  If you can tell us what these certain things are it would probably be easy to show you how to create and use the table.

The advantage of this over flat files would be that reporting, searches and pattern discernment would not have to consider multiple files (and possibly missing files).
0
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Superb, just what I needed regards
Neil
0
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Many thanks Ray, Julians post did exactly what I needed for that particular item as I'm already implimenting a solution similar to your suggestion for other logging parts.

Regards
Neil
0
 
Julian HansenCommented:
You are welcome - thanks for the points.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now