Ec (2); if you use the Active Directory instead of creating an account in the database table, you can use the account in the original Windows network. LDAP, Lightweight Directory Access Protocol (LightweightDirectoryAccessProtocol), is used to access Microsoft's Active Directory and other directory servers (DS, DirectoryServer) protocol. PHP supports LDAP by default. the following uses L script ec (2); script
If you use the Active Directory instead of creating an account in the database table, you can use the account in the original Windows network.
Lightweight Directory Access Protocol (Lightweight Directory Access Protocol) is a Protocol used to Access Microsoft's Active Directory and other Directory servers (DS, Directory Server). PHP supports LDAP by default.
The following is a PHP program that uses LDAP for user authentication. in Microsoft's Active Directory, the Unique User ID is "samaccountname", and some DS are "uid". The method is as follows:
1. Connect to the LDAP Server with the dn (such as cn = user_name, ou = web, dc = ideawu, dc = com) of the account with permissions.
2. query the dn of a logon user based on the user name.
3. Use this dn to connect to the LDAP Server. If the connection is successful, the login is successful.
Note! Microsoft's Active Directory Server can be connected successfully with an empty account (set question? Default? Exception ?)!
$ Userid = $ _ POST [''userid''];
$ User_password = $ _ POST [''password''];
If ($ userid & $ user_password ){
// Config
// $ Ldap_server = "ideawu.com ";
// $ Ldap_admin = "user_name ";
// $ Ldap_password = "xxx ";
// $ Base_cn = "ou = web, dc = ideawu, dc = com ";
$ Conn = ldap_connect ($ ldap_server );
If (! $ Conn ){
Die ("
Connection LDAP server error ");
}
$ Bind = ldap_bind ($ conn, $ ldap_admin, $ ldap_password );
If (! $ Bind ){
Die ("
Bind LDAP server error ");
}
$ Filter = ''samaccountname = ''. $ userid;
$ Attributes = array (''mail '');
$ Result = ldap_search ($ conn, $ base_dn, $ filter, $ attributes );
$ Info = ldap_get_entries ($ conn, $ result );
If (! $ Result ){
Die ("
Search failed ");
}
If ($ info ["count"]! = 0 ){
$ User_dn = $ info [0] ["dn"];
Unset ($ bind2 );
$ Bind2 = @ ldap_bind ($ conn, $ user_dn, $ user_password );
If ($ bind2 ){
// Login done. Set session
}
}
Ldap_close ($ conn );
}
</