Message Board

Bugs & Development

Older Posts ]   [ Newer Posts ]
 PHP error notices
Author: M.P2   (21 Nov 04 3:44pm)
I'm running PHP with error_reporting set to "E_ALL" (which is the recommended setting.) This reveals a few warnings in the php script...

There are a few dozen warnings like this:
Notice: Use of undefined constant __REQUEST_HOST - assumed '__REQUEST_HOST' in /home/.../myscript.php on line 50

In lines 50 through 110, the first parameter of define() needs to be in quotation marks.

Lines 190 and later generate many "undefined index" warnings.

Line 190: The condition should be: isset($_SERVER["HTTP_X_FORWARDED_FOR"])
Line 198: Need a condition similar to 190 in case Referer header isn't set.
Line 233: $request variable is not initialised before use.
Lines 251-292: As with 190, need to use isset()

The script also relys on short_open_tags being enabled. This is the default (and I don't know if anyone turns it off), but it's something to be aware of.
 
 Re: PHP error notices
Author: L.Holloway   (21 Nov 04 7:08pm)
I toggled E_ALL on and fixed all the warnings I saw. Thanks for reporting the issue. Users that have been expierencing warnings on their pots priot to this date, should generate and install a new script.
 
 Re: PHP error notices
Author: J.Cridland   (5 Dec 04 6:17pm)
However, there was still an error when I installed the script this evening: activating it, it said "$email not defined" (or something similar). And yes, I have E_ALL on...
 
 Re: PHP error notices
Author: J.Cridland   (5 Dec 04 6:46pm)

Notice: Undefined index: email in (honeypot).php on line 247

That's the exact error.
 
 Re: PHP error notices
Author: L.Holloway   (14 Jan 05 6:14pm)
This will be fixed in the next update -- scheduled to happen tomorrow. (The warning is annoying, but will not impede the pots functionality in any way)
 
 Re: PHP error notices
Author: J.Healy   (29 Jan 05 7:09am)
By the way, just a suggestion for anyone running a PHP site, do not set error reporting to E_ALL on your live site. Use this setting on your development and test servers for sure, but never configure a public-facing service to reveal any details about the inner workings of that service - that would be way too attacker-friendly.
 
 Re: PHP error notices
Author: I.Roiban   (3 Feb 05 11:06am)
Well, it is actually good to catch any error, so set the E_ALL and redirect its output to a log file or your own e-mail address like in this example:

# -------------------------------------------
define('WEBMASTER_EMAIL, 'webmaster@yourdomain.com');
define('PHP_ERROR_FILE', php_error_log.txt');
# -------------------------------------------
if (defined('PHP_ERROR_FILE')){
ini_set('error_reporting', E_ALL);
ini_set('ignore_repeated_errors', 0);
ini_set('html_errors', 0);
function e($type,$msg,$file,$line){ # custom error handler
/* this error handler is set to catch all errors and
log error, script, line, browser etc.
it also emails system administrator
*/
switch ($type) {
case 1: # E_ERROR: Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted.
log_php_error($type,$msg,$file,$line);
exit;
break;
default:
log_php_error($type,$msg,$file,$line);
break;
}
}
set_error_handler("e"); # define a custom handler
}

function log_php_error($type,$msg,$file,$line){ # custom error handler
# stop logging or sending errors if more than 10 in the past 1 minute were logged
$ok=false;
if($fp = @fopen(PHP_ERROR_FILE, "r+")){
$last_access=fread($fp,10);
$logs_ratio=fread($fp,10);
if($last_access < (time() - 60)) {$logs_ratio = 0;} # reset the ratio to zero anyways if more than 1 minute since last error log was writen/emailed
# write to the beginning of the file in order to have the last time at the top for reading faster with fread above
if($logs_ratio < 10) {$ok = true;} # 10 per minute allowed
$logs_ratio = $logs_ratio + 1;
rewind($fp);
flock($fp,LOCK_EX);
fputs($fp,time() . sprintf("%-10s", $logs_ratio) . "\n"); # write time (10 chars) and ratio (10 chars) fixed lenght to avoid shortening of the next line
flock($fp,LOCK_UN);
fclose($fp);
}
if($ok){ # if less than 10 errors logged in in the past 1 minute proceed further
$e = time() . '|' . $type . '|' . $msg . '|' . $file . '|' . $line . '|' . $_SERVER['REQUEST_URI'] . '|' . $_SERVER['REMOTE_ADDR'] . '|' . $_SERVER['HTTP_USER_AGENT'];
# write to the end of the file
if($fp = @fopen(PHP_ERROR_FILE, "a")){
flock($fp,LOCK_EX); # acquire exclusive lock (writer)
fputs($fp,$e . "\n");
flock($fp,LOCK_UN); # release lock
fclose($fp);
}
if (defined('WEBMASTER_EMAIL')){
$error_array = explode('|',$e);
$error_array[0] = date("F j, Y, g:i a",$error_array[0]);
# e-mail error log to webmaster
$body = "<pre>+" . sprintf("%'--78s", '-') . "+\n";
$body .= '|' . sprintf("%-78s", ' P H P E R R O R R E P O R T') . "|\n";
$body .= '|' . sprintf("%'--78s", '-') . "|\n";
foreach($error_array as $value){
$body .= '| ' . sprintf("%-77s", $value) . "|\n";
}
$body .= '+' . sprintf("%'--78s", '-') . "+</pre>\n";

# To send HTML mail, set the Content-type header.
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html";
# and now mail its info
mail(WEBMASTER_EMAIL,'php error',$body,$header);
}
}
}



do not follow this link

Privacy Policy | Terms of Use | About Project Honey Pot | FAQ | Cloudflare Site Protection | Contact Us

Copyright © 2004–17, Unspam Technologies, Inc. All rights reserved.

contact | wiki | email