Solved

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

Posted on 2013-06-13
5
214 Views
Last Modified: 2013-06-14
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
Comment
Question by:Neil Thompson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 56

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39244044
$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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39244338
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
 
LVL 3

Author Closing Comment

by:Neil Thompson
ID: 39247174
Superb, just what I needed regards
Neil
0
 
LVL 3

Author Comment

by:Neil Thompson
ID: 39247178
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
 
LVL 56

Expert Comment

by:Julian Hansen
ID: 39247295
You are welcome - thanks for the points.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP 5.6 and 7.x 4 39
How Close unsubmited attempts 10 44
Converting PHP triple des decrypt to c# 9 68
[form-control] Retain values after a POST action 21 33
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question