LDAP is a Protocol, which is commonly used in the following three solutions: 1NDS (NovellDirectoryServices) 2MicrosoftActiveDirectory3OpenLDAP to implement LDAP, the first step is to design DIT (DirectoryInformationTree ). The following connection code is verified under MicrosoftActiveDirectory (AD)
LDAP is a Protocol. Currently, there are three common implementations: 1 NDS (Novell Directory Services) 2 Microsoft Active Directory 3 OpenLDAP to implement LDAP, the first step is to design the DIT (Directory Information Tree ). The following connection code is verified under Microsoft Active Directory (AD)
LDAP is a Protocol. Currently, there are three common implementations:
1 NDS (Novell Directory Services)
2 Microsoft Active Directory
3 OpenLDAP
To implement LDAP, the first step is to design the DIT (Directory Information Tree ).
BelowConnectionThe code is verified under Microsoft Active Directory (AD.
The simplest bind method:
// LDAP variables
$ Ldaphost = "192.168.8.5"; // your ldap servers
$ Ldapport = 389; // your ldap server's port number
// Connecting to LDAP
$ Ldapconn = ldap_connect ($ ldaphost, $ ldapport) or die ("cocould not connect to $ ldaphost ");
$ Ldaprdn = "testuser"; // ldap rdn or dn
$ Ldappass = 'testpwd'; // associated password
If ($ ldapconn ){
// Binding to ldap server
$ Ldapbind = ldap_bind ($ ldapconn, $ ldaprdn, $ ldappass );
// Var_dump ($ ldapbind );
// Verify binding
If ($ ldapbind ){
Echo "LDAP bind successful ...";
} Else {
Echo "LDAP bind failed ...";
}
}
Whether this method can be used depends on the structure of the Directory Information Tree. This method has obvious disadvantages: either bind succeeded or failed. That is, it cannot be a user name error or a Password error.
Search Method:
$ Ldap_host = "192.168.8.5 ";
$ Ldap_port = "389 ";
$ Base_dn = "OU = zzz, DC = test, DC = com, DC = cn ";
$ Filter = "(cn = *)";
$ Ldap_user = "cn = admin, OU = zzz, DC = test, DC = com, DC = cn ";
$ Ldap_pass = "123456 ";
$ Connect = ldap_connect ($ ldap_host, $ ldap_port );
Ldap_set_option ($ connect, LDAP_OPT_PROTOCOL_VERSION, 3 );
$ Bind = ldap_bind ($ connect, $ ldap_user, $ ldap_pass );
$ Read = ldap_search ($ connect, $ base_dn, $ filter );
$ Info = ldap_get_entries ($ connect, $ read );
Echo $ info ["count"]. "entrees retournees
";
For ($ ligne = 0; $ ligne <$ info ["count"]; $ ligne ++)
{
For ($ colonne = 0; $ colonne <$ info [$ ligne] ["count"]; $ colonne ++)
{
$ Data = $ info [$ ligne] [$ colonne];
Echo $ data. ":". $ info [$ ligne] [$ data] [0]."
";
}
Echo"
";
}
Ldap_close ($ connect );
Where:
$ Ldap_user = "cn = admin, OU = zzz, DC = test, DC = com, DC = cn ";
$ Ldap_pass = "123456 ";
These two statements define a dedicated LDAP account used to log on to LDAPServer, This account must haveSearchPermission.
Log on to LDAPServerThen, you canInformationProceedSearch(Ldap_search), you can determine whether an id exists, whether the password is correct, and so on.
The method used in specific development depends on the design of the Directory Information Tree.