[]$log=fopen("/home/public_html/ubbthreads/log.html","a");
fwrite($log,"$msg<br>\n");
fclose($log);[/]
This could be replaced with:
error_log("$msg<br>\n", 3, '/home/public_html/ubbthreads/log.html');
You probably wouldn't want that file to be publicly readable. I suggest making the log file a config parameter, e.g.:
error_log("$msg<br>\n", 3, $config['midetect_log']);