What are some potential pitfalls when using LDAP for user authentication in PHP?

One potential pitfall when using LDAP for user authentication in PHP is not properly securing the connection to the LDAP server, which could lead to sensitive information being exposed. To solve this issue, it is important to use secure protocols such as LDAPS and properly configure the connection settings.

$ldapServer = 'ldaps://ldap.example.com';
$ldapPort = 636;

$ldapConn = ldap_connect($ldapServer, $ldapPort);
ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapConn, LDAP_OPT_REFERRALS, 0);