Solved

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

Posted on 2013-06-13
5
200 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:NeilT
  • 2
  • 2
5 Comments
 
LVL 51

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 108

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:NeilT
ID: 39247174
Superb, just what I needed regards
Neil
0
 
LVL 3

Author Comment

by:NeilT
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 51

Expert Comment

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now