skip to Main Content

How To Create The Log File Using PHP

How to create the log file using PHP


How to create the log file using PHP. Many times we need to create the user log file who visit the website or else create the log file for error logs customer getting on the website. So let’s see the example how we can create the log file.

Let’s see the easy way to create the log file daily using code.

$log  = date("m/d/Y H:i:s A")."    ".$_SERVER['HTTP_USER_AGENT']."    ".$_SERVER['REMOTE_ADDR']."    "..PHP_EOL;
file_put_contents('logs/log_'.date("m.d.Y").'.txt', $log, FILE_APPEND);

This code creates the new file daily and stores the log detail. It’s store the user IP address and browser or operating system details.

So it’s too easy to store the logs using PHP.

Saroj

I am a web designer and developer part-time blogger. Write something on some free time. Find my every day thought here :)

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top