抑制虚假PHP imap_open()注意:不安全的服务器通告了AUTH = PLAIN

时间:2012-03-19 07:03:19

标签: imap php

我在日志文件中弄乱了这些虚假警告,我想在不压制合法邮件的情况下压制它们:

PHP注意:未知:安全问题:不安全的服务器在第0行的未知中宣告AUTH = PLAIN(errflg = 1)

(我正在连接到只在没有第三方用户的服务器上侦听localhost的IMAP服务。)

3 个答案:

答案 0 :(得分:15)

您可以做的一件事是使用imap_errorsimap_alerts函数,将此代码放在imap_close之前。

imap_errors();
imap_alerts();

这些功能的作用是返回已发生的所有错误和警报,然后将其刷新。如果你不调用这些函数,当调用imap_close()或页面死亡时,它们将作为通知发出。

答案 1 :(得分:2)

正如deceze所说,它并不是真正的"虚假"消息,它只是意味着它是一个明文未加密的连接。 您可以这样做:

$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');
}

答案 2 :(得分:1)

您可以在使用此功能抑制通知的同时获取所有警告和错误:

error_reporting(E_ALL & ~E_NOTICE & ~E_USER_NOTICE);

位级错误报告标志是:

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
###############################################################################

您也可以将ignore_repeated_errors设置为TRUE / 1,这样它也不会淹没您的日志。

ini_set('ignore_repeated_errors',1);