Suppress bogus PHP imap_open() Notice: insecure server advertised AUTH=PLAIN
Asked Answered
R

3

10

I'm getting a mess of these bogus warnings in my log file, and I’d like to suppress them without suppressing legitimate messages:

PHP Notice: Unknown: SECURITY PROBLEM: insecure server advertised AUTH=PLAIN (errflg=1) in Unknown on line 0

(I’m connecting to an IMAP service that is only listening to localhost on a server with no third-party users.)

Redman answered 19/3, 2012 at 7:3 Comment(2)
It's not really a "bogus" message, just one you want to knowingly ignore. If nobody can come up with an ini setting to suppress this particular notice, probably the only thing you can do is to temporarily override the error handler, string match this particular error and drop it.Regale
Well, I suppose the same thing might be said if it spit out a message every time I divided 3 by 2. I would choose to “knowingly ignore” that one, too. AFAICT, the message bypasses the error handler. (Because its source is “Unknown”?)Redman
S
20

One thing you can do is use the imap_errors and imap_alerts functions, place this code before your imap_close.

imap_errors();
imap_alerts();

What these functions do is return all errors and alerts that have occured and then flushes them. If you do not call these functions they are issued as notices when imap_close() is called, or the page dies.

Steffi answered 17/7, 2012 at 1:36 Comment(1)
do I understand this right, that these functions are required when using IMAP?Trickster
C
2

As deceze said, it's not really a "bogus" message, it just means that it's a plaintext unencrypted connection. Here is how you can do :

$error = imap_errors();
if (count($error) > 1 || $error[0] != 'SECURITY PROBLEM: insecure server advertised AUTH=PLAIN') {
  // More than 1 error or not the expected error
  var_dump($error);
  throw new Exception('IMAP error detected');
}
Chromatogram answered 20/8, 2013 at 9:19 Comment(0)
O
1

You can get all warnings and errors while suppressing notices using this:

error_reporting(E_ALL & ~E_NOTICE & ~E_USER_NOTICE);

The bit-level error reporting flags are:

Error Bit           Purpose
###############################################################################
E_ALL               All errors and warnings (doesn't include E_STRICT)
###############################################################################
E_ERROR             Fatal run-time errors
###############################################################################
E_WARNING           Run-time warnings (non-fatal errors)
###############################################################################
E_PARSE             Compile-time parse errors
###############################################################################
E_NOTICE            Run-time notices (these are warnings which often result 
                    from a bug in your code, but it's possible that it was 
                    intentional (e.g., using an uninitialized variable and 
                    relying on the fact it's automatically initialized to 
                    an empty string)
###############################################################################
E_STRICT            Run-time notices, enable to have PHP suggest changes to 
                    your code which will ensure the best interoperability 
                    and forward compatibility of your code.
###############################################################################
E_CORE_ERROR        Fatal errors that occur during PHP's initial startup
###############################################################################
E_CORE_WARNING      Warnings (non-fatal errors) that occur during PHP's 
                    initial startup
###############################################################################
E_COMPILE_ERROR     Fatal compile-time errors
###############################################################################
E_COMPILE_WARNING   Compile-time warnings (non-fatal errors)
###############################################################################
E_USER_ERROR        User-generated error message
###############################################################################
E_USER_WARNING      User-generated warning message
###############################################################################
E_USER_NOTICE       User-generated notice message
###############################################################################

You can also set ignore_repeated_errors to TRUE/1 so that it doesn't flood your log as well.

ini_set('ignore_repeated_errors',1);
Organization answered 19/3, 2012 at 7:47 Comment(3)
Downvoted. Please re-read the question, particularly at “without suppressing legitimate messages”.Redman
Oh right, because there is programmatic way to decide what is personally relevant to you and throw out everything else? That'll be the day. FYI: Legitimate is a subjective word.Organization
I agree that your answer might answer questions other than this one. In this instance, it doesn't matter what I consider to be legitimate notice messages, as your solution masks them all.Redman

© 2022 - 2024 — McMap. All rights reserved.