天天看點

php 使用ldap,PHP LDAP連接配接

當您嘗試執行ldap_bind時,您隻是連接配接并确定憑據是否有效。您需要做的是将您的域添加到使用者名并讓它連接配接。然後,如果您想确定使用者是否是帶有ldap_search()的'技術'OU,請考慮這樣做:

$domain = 'mydomain.com';

$username = 'josue.ruiz';

$password = 'pass';

$ldapconfig['host'] = '10.10.10.11';

$ldapconfig['port'] = 389;

$ldapconfig['basedn'] = 'dc=domain,dc=com';

$ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);

ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);

ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);

$dn="ou=Technology,".$ldapconfig['basedn'];

$bind=ldap_bind($ds, $username .'@' .$domain, $password);

$isITuser = ldap_search($bind,$dn,'(&(objectClass=User)(sAMAccountName=' . $username. '))');

if ($isITuser) {

echo("Login correct");

} else {

echo("Login incorrect");

}