Ldap_search () [Function.ldap-search]: search:operatio_n_s error [

Source: Internet
Author: User
Tags ldap ad server samaccountname
LDAP AD domain authentication ...

I can use the normal mode, including querying the user.
But today write a class, quote ldap_search () [Function.ldap-search]: search:operatio_n_s error

The code for the class is as follows

$ldapDN, this is the right one ...
Ldapbind () is also able to verify username and password ...
But the query of this user's details will be an error, the internet is prompted because the ad domain does not support anonymous, but I added the verification in search ... Also also reported wrong ...

When you do not use the class, Ldap_bind () is available ... Look at the following piece of code

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 = $ldapDo        Min        $this->ldaphost = $ldapHost;        $this->ldapport = $ldapPort;        $this->username = $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->p assword)) {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);        Get 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"; Defines the column used for the query $filter _val = $userName; Defines the value used to match $result = Ldap_search ($ldap _conn, $base _dn, "($filter _col= $filter _val)"); Execute Query $entry = ldap_get_entries ($ldap _conn, $result);                Get query Results $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)

Let's see if the arguments are passed correctly after you use the class, is the argument right?

The parameters are the same ....
So it's strange ...

Problem solved ...
Or the issue of the certification ...

I don't know if it can be said to be a threading problem ...
Before calling Ldap_search, you must satisfy the link to the LDAP server and pass the Ldap_bind authentication ...

And in function, after Ldap_bind, then Ldap_search, again link LDAP server, generated resource ID is not the same ... And this Resouce ID is not ldap_bind certified ...

So the way to change that is
When calling the function of GetUserInfo, we need to re-link the LDAP server again and obtain the user information through authentication, so that the error will not be ...

  • 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.