**Hi everyone,**

I know my question must have a deja-vue side but I didn't find any solutions through stackoverflow or else.
So I've been trying to create a function that allows a connection to ldap, then check the id and pwd of my user and then check in which group he is.
When I did this function in one "piece", it worked.
But I wanted to do this in three diferent functions so I can deal with it one by one.
So now I have the function that connects to ldap:

```
   function ldapConnection() {
    $ldapConnection = ldap_connect(LDAP_SERVER);
    ldap_set_option($ldapConnection, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ldapConnection, LDAP_OPT_REFERRALS, 0);
    return $ldapConnection;
}

```

It returns an identifier LDAP link so the connection is ok.

Then I have the function that check the login and pwd :

```
  public function checkLoginPwd($login, $pwd) {
    $ldapConnexion = $this->ldapConnection();
    if ($bind = ldap_bind($ldapConnexion, $login, $pwd)) {
        return true;
        //ldap_close($ldapConnexion);
    } else {
        return false;
    }
}

```

And then the function I've got trouble with.

```
    public function checkUserRights($login, $pwd, $ldapConnection) {   
    //Récupération login
    $loginAccount = "(sAMAccountName=$login)";
    //Suppression de "myGroup\"
    $filter = str_replace("myGroup\\", "", $loginAccount);
    $attr = array("memberof");
    //Recherche
    $result = ldap_search($ldapConnection, LDAP_BASE_DN, $filter, $attr);
    $entries = ldap_get_entries(ldap_connect(LDAP_SERVER), $result);

    foreach ($entries[0]['memberof'] as $grps) {
        if (strpos($grps, "VPN")) {
            $access = 2;
            break;
        }

        if (strpos($grps, "Users"))
            $access = 0;
    }

    if ($access != 0) {
        $_SESSION['user'] = $login;
        $_SESSION['access'] = $access;
        return true;
    } else {
        return false;
    }

```

If I try to connect this way, I have this message error:
ldap\_search(): Search: Operations error
Even if it does work if I do it in one time.

If anyone could help me, that would be great....

EDIT : 

So you know, if I do a var dump of $filter I have this : string'(sAMAccountName=myLogin)'.
For $ldapConnection it's resource(13, ldap link), for LDAP\_BASE\_DN it's string 'DC=myGroup, DC=fr', and $attr is array (size=1)
 0 => string 'memberof' (length=8).