Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-06-13
5
Medium Priority
?
220 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 59

Accepted Solution

by:
Julian Hansen earned 2000 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 111

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 59

Expert Comment

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

660 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