Ldap_search () [function. ldap-search]: Search: Operatio_n_serror [

Source: Internet
Author: User
Ldap_search () [function. ldap-search]: Search: Operatio_n_serror [ldap ad domain verification...

I can use common modes, including querying users ..
But write a class today and report ldap_search () [function. ldap-search]: Search: Operatio_n_s error.

The class code is as follows:

$ LdapDN. this is correct...
LdapBind () can also verify the user name and password...
However, an error will be reported when you query the details of this user. the error message is displayed on the Internet because the AD domain does not support anonymity. However, an error is reported when I add the verification in search...

Ldap_bind () is okay when no class is needed...

Class userldap {private $ ldapHost; // AD server address private $ ldapPort; // AD server port private $ ldapDomin; // AD domain private $ ldapDN = "OU = Users, OU = xxx, OU = abc, DC = adv, DC = ccc, DC = com "; // User list location private $ userName; private $ passWord; public function _ construct ($ ldapDomin, $ ldapHost, $ ldapPort, $ userName, $ passWord) {$ this-> ldapDomin = $ ldapDomin; $ this-> ldapHost = $ ldapHost; $ this-> ldapPort = $ ldapPort; $ this-> userN Ame = $ userName; $ this-> passWord = $ passWord;} private function ldapConnect () {if (! $ This-> ldapConn = ldap_connect ($ this-> ldapHost, $ this-> ldapPort) {$ this-> showerror = ldap_error ($ this-> ldapConn );} else {$ this-> ldapConn = ldap_connect ($ this-> ldapHost, $ this-> ldapPort);} return $ this-> ldapConn;} public function ldapBind () {if (@ ldap_bind ($ this-> ldapConnect (), $ this-> ldapDomin. '\\'. $ this-> userName, $ this-> passWord) {ldap_bind ($ this-> ldapConnect (), $ this-> ldapDomin. '\\'. $ this-> userName, $ this-> passWord); return TRUE;} else {return FALSE;} public function getUserinfo () {if ($ this-> ldapBind ()) {ldap_bind ($ this-> ldapConnect (), $ this-> ldapDomin. '\\'. $ this-> userName, $ this-> passWord); $ this-> adResult = ldap_search ($ this-> ldapConnect (), $ this-> ldapDN, "(sAMAccountName = $ this-> userName)"); $ this-> userInfo = ldap_get_entries ($ this-> ldapConnect (), $ this-> adResult ); // Obtain the query result} else {$ this-> userInfo = "NA";} return $ this-> userInfo ;}}



If (! $ Ldap_conn = ldap_connect ($ ldap_host, $ ldap_port) {$ tip = "ladp host ". $ ldap_host. "cannot connect";} else {if (@ ldap_bind ($ ldap_conn, $ doMain. '\\'. $ userName, $ passWord) {$ query = $ db-> select ("bp_user", "userFullname", "where userNT = '$ username '"); if ($ row = $ db-> fetch_array ($ query) {$ _ SESSION ['username'] = $ row ['0']; $ _ SESSION ['password'] = $ passwordDb; $ db-> update ("bp_user", "userPassword = '$ passworddb', userLogin = userLogin + 1, userLoginip = INET_ATON ('$ lastip'), userUpdate =' $ nowtime' "," where userNT = '$ username' "); ldap_unbind ($ ldap_conn) or die ("Can't unbind from LDAP server. "); $ msg =" USERNAME ". $ row [0]. "Login In OK"; unset ($ query); unset ($ row); Get_admin_msg ($ lastUrl, $ msg, 'main ');} else {$ base_dn = "OU = Users, OU = xxx, OU = abc, DC = adv, DC = ccc, DC = com"; $ filter_col = "sAMAccountName "; // define the column $ filter_val = $ userName; // define the value for matching $ result = ldap_search ($ ldap_conn, $ base_dn, "($ filter_col = $ filter_val) "); // execute the query $ entry = ldap_get_entries ($ ldap_conn, $ result ); // Obtain the query result $ userFullname = strtoupper ($ entry [0] ['cn'] [0]); $ userEmail = $ entry [0] ['mail'] [0]; $ userDept = $ entry [0] ['Department '] [0]; $ userCustomer = $ entry [0] ['roomnumber'] [0]; $ entry = NULL; $ result = NULL; ldap_unbind ($ ldap_conn) or die ("Can't unbind from LDAP server. "); $ query = NULL; $ row = NULL ;}


Reply to discussion (solution)

Then you can check whether the parameter is correctly passed after the class is used, that is, the parameter is correct.

Parameters are the same ....
So it's strange...

Solve the problem...
Or the authentication issue...

I don't know if it can be said to be a thread problem...
Before you call ldap_search, you must link to the ldap server and pass the ldap_bind authentication...

In the function, when ldap_bind and Ldap_search are performed again, the generated resource ID is different when the ldap server is linked again... and the resouce ID does not undergo ldap_bind authentication...

So the modification method is
When calling this function of getUserinfo, you need to re-connect to the ldap server and obtain the user information after authentication, so that no error is reported...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.