note 124788 added to function.ldap-connect
| From: | nateshull at gmail dot com | Date: | Tue, 03 Mar 2020 19:26:19 +0000 |
| Subject: | note 124788 added to function.ldap-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214276@lists.php.net to get a copy of this message | ||
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";
//options are require, never, allow
//require is most secure, the others could allow for man in the middle attacks
putenv('LDAPTLS_REQCERT=require');
//tell ldap where the root ca certificate is
//note that the space is allowed in the path without escape or quotes
//I have not tested the permissions, but I would assume the service should have read.
putenv('LDAPTLS_CACERT=C:\\Program Files\\php\\certs\\rootca.pem');
//test to ensure the certificate is able to be read and path is right.
echo file_get_contents("LDAPTLS_CACERT=C:\\Program Files\\php\\certs\\rootca.pem");
// Set debugging
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
// connect to ldap server
$ldapconn = ldap_connect($ldapserver) or die ("Couldn't connect");
// binding to ldap server
$ldapbind = false;
$ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass);
//easy view of success or failure
if ($ldapbind) {
print("\n logged in! \n\n");
} else {
print("\n log on failure \n\n");
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 38.142.137.34 (proxied: 72.10.207.12)
----
Manual Page -- http://php.net/manual/en/function.ldap-connect.php
Edit -- https://master.php.net/note/edit/124788
Del: integrated -- https://master.php.net/note/delete/124788/integrated
Del: useless -- https://master.php.net/note/delete/124788/useless
Del: bad code -- https://master.php.net/note/delete/124788/bad+code
Del: spam -- https://master.php.net/note/delete/124788/spam
Del: non-english -- https://master.php.net/note/delete/124788/non-english
Del: in docs -- https://master.php.net/note/delete/124788/in+docs
Del: other reasons-- https://master.php.net/note/delete/124788
Reject -- https://master.php.net/note/reject/124788
Search -- https://master.php.net/manage/user-notes.php