title: How can i manage an ldap_search() Operations error?
body: <p>I'm trying to use an LDAP query to get my AD groups of one of my divisions, I've written this for the moment:</p>
  
  <pre><code>&lt;?php
      session_start();
  //::::::::DEBUG::::::::\\
      //echo $_SESSION['login_session'];
      //echo "&lt;br&gt;";
      //echo $_SESSION['password_session'];
      //echo "&lt;br&gt;";
      //echo $_SESSION['AD_session'];
      //$_SESSION['AD_session']=ldap_conect(XXX.XXX.XXX,389) but i apparently cannot conserve this function in a $_SESSION var...
      //echo "&lt;br&gt;";
      //echo $_SESSION['DN_SESSION'];
      //"OU=XXX,DC=XXX,DC=XXX"
      //echo "&lt;br&gt;";
  //::::::::DEBUG::::::::\\ 
  
  //----------------------------------------------------------------------------------------------------
  
  //::::::::SECURITY FUNCTION::::::::\\
      if (NULL!==($_SESSION['login_session']&amp;&amp;$_SESSION['password_session'])){
  //::::::::SECURITY FUNCTION::::::::\\
  
  //----------------------------------------------------------------------------------------------------
  
  //::::::::VARIABLES::::::::\\
          $filter = "(CN=*)";
          $attr = array("OU","CN","DC");
  //::::::::VARIABLES::::::::\\
  
  //----------------------------------------------------------------------------------------------------
  
  //::::::::LDAP's setting::::::::\\
  
          ldap_set_option(ldap_connect("XXX.XXX.XXX",389), LDAP_OPT_PROTOCOL_VERSION, 3);
          ldap_set_option(ldap_connect("XXX.XXX.XXX",389), LDAP_OPT_REFERRALS, 0);
  
  //::::::::LDAP's setting::::::::\\
  
  //----------------------------------------------------------------------------------------------------
  
  //::::::::LDAP BIND::::::::\\
  
          ldap_bind(ldap_connect("XXX.XXX.XXX",389),"CN=".$_SESSION['login_session'].",OU=XXX,OU=XXX,DC=XXX,DC=XXX", $_SESSION['password_session']);
  
  //::::::::LDAP BIND::::::::\\ 
  
  //----------------------------------------------------------------------------------------------------
  
  //::::::::REQUESTS VARIABLES::::::::\\      
          $result = ldap_search(ldap_connect("XXX.XXX.XXX",389),$_SESSION['DN_SESSION'], $filter, $attr);
  
          $rescount = ldap_count_entries(ldap_connect("XXX.XXX.XXX",389),$result);
  
          $data = ldap_get_entries(ldap_connect("XXX.XXX.XXX",389),$result);
  //::::::::REQUESTS VARIABLES::::::::\\
  
  //----------------------------------------------------------------------------------------------------
  
  //::::::::RESULTS DISPLAY::::::::\\      
          echo '&lt;pre&gt;';
  
          foreach($data as $row) {
  
          print_r($row);
  
          }
  //::::::::RESULTS DISPLAY::::::::\\
  
  //----------------------------------------------------------------------------------------------------
      ?&gt;
  
  </code></pre>
  
  <p>The binding function is working well and I'm using a valid user to query my AD groups. But I get an "ldap_search(): Search: Operations error" message on my ldap_search query. I've searched for a moment on different forums and I saw some solutions: setting the protocol and referral of the AD, which I've done in my LDAP's setting part, I also saw that some people get this error because they were using DN instead of DC in the distinguished name that they wanted to reach but it is not my case... </p>
  
  <p>Is someone have an idea of what's the problem in my code ? Thanks a lot.</p>