I'm trying to use the following script given to me by 1and1 to generate an error log for php. This code is not creating a new file or updating the file even if I create it manually.
//set time zone of website date_default_timezone_set("America/New_York"); //Set error warning for active or non-active site if($SiteIsActive=="no"){ error_reporting(E_ALL); } else{ error_reporting(0); $old_error_handler = set_error_handler("userErrorHandler"); function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars){ $time=date("d M Y H:i:s"); // Get the error type from the error number $errortype = array (1 => "Error", 2 => "Warning", 4 => "Parsing Error", 8 => "Notice", 16 => "Core Error", 32 => "Core Warning", 64 => "Compile Error", 128 => "Compile Warning", 256 => "User Error", 512 => "User Warning", 1024 => "User Notice"); $errlevel=$errortype[$errno]; var_dump($errno); var_dump($errmsg); var_dump($filename); var_dump($linenum); //Write error to log file (CSV format) $errfile=fopen("errors.csv","a"); fputs($errfile,"\"$time\",\"$filename: $linenum\",\"($errlevel) $errmsg\"\r\n"); fclose($errfile); if($errno!=2 && $errno!=8){ //Terminate script if fatal error die("A fatal error has occurred. Script execution has been aborted"); } } }
This code is included into other scripts where it sets the error handling for those scripts. It works fine to determine if the error_reporting should be turned on (for debugging) or off when the site is active. But it won't generate the error log file. The var_dumps in there produce nothing at all. I know there is an error in the code, because I went out of my way to create one. And when the site is in debug mode it shows the errors as it should.