Implementing LDAPS on a WISP stack - Win, IIS, SQL, PHP
PHP 7.0.19:
Had some issues with some of the instructions and I needed LDAPS for an upcoming Active Directory update that removes insecure LDAP connections.
Enable modules for ldap and openssl in php.ini
Also ensure the extensions are in the ext folder
Verify the modules are loaded: phpinfo()
Notes:
The ldap or openssl config file is not needed if the environment variables are set in the code. Also the ca path does not like double quotations around the path.
*** code sample:
<?php
$ldapuser = "domain\\user";
$ldappass = "Passsword";
$ldapserver = "ldaps://server.domain.com";
putenv('LDAPTLS_REQCERT=require');
putenv('LDAPTLS_CACERT=C:\\Program Files\\php\\certs\\rootca.pem');
echo file_get_contents("LDAPTLS_CACERT=C:\\Program Files\\php\\certs\\rootca.pem");
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
$ldapconn = ldap_connect($ldapserver) or die ("Couldn't connect");
$ldapbind = false;
$ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass);
if ($ldapbind) {
print("\n logged in! \n\n");
} else {
print("\n log on failure \n\n");
}
?>