title: LDAP modify active directory multiple OU search
body: <p>I have this script that works fine when i only use one OU. But as soon as i put the $ldapbase in an array and define multiple OU's it stops working @ the ldap_get_entries and the ldap_modify. I know why but not sure how to modify the code accordingly.</p>
  
  <p>Is there a way of either seaching the whole forest root instead of having to define the OU, or just getting the OU of the samaccountname=$username.</p>
  
  <pre><code> &lt;?php
      $username=$_GET['username']; 
  
      if(isset($_POST['printpin'])) {
  
      $printpin=$_POST['printpin'];   
      $domadlogin = 'admin@dom.co.uk';
      $domadpw = 'pass';
  
      $ldapServer = "dc.dom.co.uk";
  
      $ldapBase[] = "OU=Users1,DC=dom,DC=co,DC=uk";
      $ldapBase[] = "OU=Users2,DC=dom,DC=co,DC=uk";
      $ldapBase[] = "OU=Users3,DC=dom,DC=co,DC=uk";
  
      $ds = ldap_connect($ldapServer);
      if (!$ds) {die('Cannot Connect to LDAP server');}
  
      $ldapBind = ldap_bind($ds,$domadlogin,$domadpw);
      if (!$ldapBind) {die('Cannot Bind to LDAP server');}
  
      ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
      ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
  
      foreach($ldapBase as $dn){ 
      $sr = ldap_search($ds, $dn, "(samaccountname=$username)");
      }
  
      $ent= ldap_get_entries($ds,$sr);
      $dn=$ent[0]["dn"];
      $newinfo['primaryTelexNumber']= $printpin;
  
      $save = ldap_modify($ds, $dn, $newinfo);
  
      if (!$save) {die('Cannot save to LDAP server');}
      ?&gt;
  
      &lt;p&gt;Your new PIN number has now been set.&lt;/p&gt;
      &lt;p&gt;Username:&amp;nbsp;&lt;?php echo $username; ?&gt;&lt;br /&gt;PIN:&lt;?php echo $printpin; ?&gt;&lt;/p&gt;
  
      &lt;?php
      }
      else {
      ?&gt;
  
      &lt;p&gt;Username:&amp;nbsp;&lt;?php echo $username; ?&gt;&lt;/p&gt;
      &lt;form action="pin.php?username=&lt;?php echo $username; ?&gt;" method="POST"&gt;
      PIN: &lt;input type="text" name="printpin" title="printpin"/&gt;
      &lt;input type="hidden" name="username" value="&lt;?php echo $username; ?&gt;"/&gt;
      &lt;input type="submit" value="Save"&gt;
      &lt;/form&gt; 
  
  
      &lt;?php
      }
      ?&gt;
  </code></pre>
  
  <p>Any help much appreciated.</p>