What are some common issues when establishing a secure LDAPS connection in PHP using XAMPP and OpenSSL?

One common issue when establishing a secure LDAPS connection in PHP using XAMPP and OpenSSL is the "unable to get local issuer certificate" error. This error occurs when PHP cannot verify the SSL certificate of the LDAP server. To solve this issue, you can manually specify the path to the CA certificate file in your PHP code.

// Specify the path to the CA certificate file
$ldapServer = 'ldaps://your-ldap-server';
$ldapPort = 636;
$ldaprdn = 'your-ldap-user';
$ldappass = 'your-ldap-password';
$caCertPath = 'C:/xampp/apache/bin/cacert.pem';

// Establish LDAPS connection
$ldapconn = ldap_connect($ldapServer, $ldapPort);

// Set options for LDAPS connection
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

// Bind to LDAP server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

if ($ldapbind) {
    echo "LDAP bind successful";
} else {
    echo "LDAP bind failed";
}

// Close LDAP connection
ldap_close($ldapconn);