How can PHP be used to store information in a text file for logging purposes?

To store information in a text file for logging purposes using PHP, you can open a file in append mode and write the desired information to it. This allows you to keep track of important events or data in your application for debugging or monitoring purposes.

<?php
$logFile = 'log.txt';
$logMessage = "User logged in at " . date('Y-m-d H:i:s') . "\n";

file_put_contents($logFile, $logMessage, FILE_APPEND);
?>