![](/img/trans.png)
[英]PHP Warning: ldap_bind(): Unable to bind to server: invalid credentials
[英]php ldap bind warning
當ldap_bind上的憑證無效但沒有使用@ldap_bind或error_reporting設置為0時,是否有可能避免在屏幕上顯示php警告?
我嘗試過:
try {
if(!ldap_bind($ds, $binddn, $password)) {
throw new Exception('Invalid credentials');
}
} catch (Exception $e) {
var_dump($e->getMessage());
}
但這是行不通的。 屏幕上仍然顯示PHP警告。
有人知道解決方案嗎?
看看http://php.net/manual/de/errorfunc.configuration.php#ini.display-errors
與ldap擴展無關,但與您的php設置無關。 您應該在php.ini中使用log_errors
將錯誤記錄到錯誤日志中。
並且由於ldap-extension當前不會引發異常,因此將ldap_bind
包裝到try-catch
-Block中不會帶來太多的運氣。 不過,您可以在調用任何ldap函數之前添加一個自定義錯誤處理程序,並將其替換為默認錯誤處理程序。
為此,請訪問http://php.net/manual/de/function.set-error-handler.php和https://github.com/zendframework/zend-ldap/blob/master/src/Ldap。 php#L825-L827
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.