Write to a file from PHP

I probably covered this before, but I want to keep some log files of what is happening on various pages on a site. I could write to the php error log, but I look at those every morning and then erase them. I want something that sticks around but I don’t need a whole lot.

This solution works for me.

 $fname = "./interesting_stuff.log";
 $info = "Message";
 $fp = fopen($fname, 'w');
 fwrite ($fp, "$info" . "\r");

You’ll need to create the file and set the permissions so everyone can write to it before it will work.

Leave a Reply

You must be logged in to post a comment.

Well Golly

Atheism Plus

Buy from Amazon