Jump to content

1and1 Shared Host + Error Log File


AJinNYC

Recommended Posts

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!={
//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.

Edited by AJinNYC
Link to comment
Share on other sites

What kind of error did you create? Some errors are not catchable via PHP code so a custom error handler for error logging would not trigger for them. This includes a Parse error for example, as if PHP cannot parse the file there is no way for it to run it in order to execute the error handler function.

Link to comment
Share on other sites

I triggered an error on a custom made mysqli_sanitize function (basically a function to escape mysql data). The function requires two arguments and I only entered one. So the error is something like argument 2 is missing from function mysqli_sanitize. 

function mysqli_sanitize($link, $value){
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { 
$value=stripslashes($value);
}
return mysqli_real_escape_string($link, $value);
}

I entered the below to trigger the error:

mysqli_sanitize(1);
Edited by AJinNYC
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.