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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s