PHP Function LDAP_Error Part 2
In the first part of this article series on LDAP, I gave a crash course in PHP’s support for LDAP, demonstrating how to create and query an LDAP directory server for user information. This second article looks at the php function ldap_error, which allows you to trap and handle errors in your PHP-LDAP scripts.
Functions are a powerful tool in any programming language, and PHP is no exception. They allow you to write code that is modular and reusable. Whether they come from the standard PHP distribution or from additional extensions compiled with PHP, they are an important part of the language.
PHP functions are named with the keyword function followed by the name of the function and closed parenthesis. The function code is defined inside the parentheses, and any variables or other pieces of data that are used in the function must be declared before the function is called. Functions are a way to break up complex and repetitive code into smaller, more manageable chunks.
The ldap_error function returns an error message (in text form) explaining the LDAP errno number that was returned by ldap_bind. This is useful, because some software checks only the errno return value without seeing if the bind was successfully executed. For example, when you try to bind to an LDAP server using a password but the connection is rejected by the LDAP library, you will get the errno 87 message. This is a common security vulnerability that can be easily exploited by hackers using Burpsuite or other similar tools.