#native_company# #native_desc#
#native_cta#

File based, custom logging Page 4

By John Starkey
on September 30, 2002

Full Source!
Here is the code in whole so that you may paste it in a file for demonstration purposes:

<?php

$log_file 
'/whatever.file';  // change this to a file the server can write to, and you can read

$date date('Y-m-d H:i:s (T)');

function 
simplisticErrorHandler($errno$errmsg$filename$linenum$vars)

{

    global 
$log_file$date;

    if ( 
$errno == E_USER_NOTICE )

    {

        
$err "$date - ".$_SERVER['REMOTE_ADDR']." - NOTICE: $errmsg in $filename on line $linenumn";

        
error_log($err,3,$log_file);

    }

}

set_error_handler("simplisticErrorHandler");

$fake_array 'test'// declare the variable with a string value;

if ( !in_array('Something'$fake_array ) ) // cause the faked array to throw an error

{

    
trigger_error("Look, you and I both know that wasn't an array",E_USER_NOTICE); 

    echo 
"An error has been posted to $log_file";

}

?>



Once you have pasted the above code into a file, you can open that file in your browser and it should
print an error to your log file, as well as echo “An error has been posted to /tmp/article.log” to
your browser. If this is not the case, there may be a permissions problem, or you may need to check
your syntax.