Zend - The PHP Company




Miscellaneous

Add Code


Append a string to a log  

Type: code fragment
Added by: sync1
Entered: 29/07/2000
Last modified: 08/12/1999
Rating: - (fewer than 3 votes)
Views: 6184
Function that appends a string to a specified log file.


<?php
function append_to_log($logstr)
{
        
$timestamp date("M d H:i:s");
        
$path "/path/to/log/";
        
$logfile "filename.log";
        
        
$log_append_str "$timestamp " .$logstr;
        
        if(
file_exists($path.$logfile) && is_writeable($path.$logfile))
        {
                
$fp fopen($path.$logfile'a+');
                
fputs($fp"$log_append_strrn");
                
fclose($fp);
        }
        else if(!
file_exists($path.$logfile) && is_writeable($path))
        {
                
touch($path.$logfile);
                
chmod($path.$logfile0600);
                
$fp fopen($path.$logfile'a+');
                
fputs($fp"$log_append_strrn");
                
fclose($fp);
        }
        else
        {
                die(
"Unable to write to file..");
        }       
}
?>


Usage Example


$logstr = "text to append to log";

append_to_log($logstr);


Rate This Script





Search



This Category All Categories