title: Warning: ldap_search(): Search: Bad search filter
body: <p>I am trying to create a login page using PHP. </p>
  
  <p>Goals: <br/><br/>
  1. The user is able to sign in using the same username/password he uses when logging into Windows <br/>
  2. The user will be redirected to a page depending on the group he belongs to</p>
  
  <p>So the 1st goal is solved. The problem now is the 2nd goal.</p>
  
  <p>I get an error when I run the script:</p>
  
  <pre><code>Warning: ldap_search(): Search: Bad search filter
  </code></pre>
  
  <p>Script:</p>
  
  <pre><code>$ldap['user'] = "domain\user123";
  $ldap['pass'] = "password123";
  $ldap['host']   = 'site.domain.com';
  $ldap['port']   = 389;
  $ldap['dn'] = "DC=site, DC=domain, DC=com";
  $ldap_user_group = "User";
  $ldap_manager_group = "Admin";
  
  $ldap['conn'] = ldap_connect( $ldap['host'], $ldap['port'] )
  or die("Could not connect to {$ldap['host']}" );
  
  $ldap['bind'] = ldap_bind($ldap['conn'], $ldap['user'], $ldap['pass']);
  
  if( !$ldap['bind'] )
    {
      echo "Login Failed";
    }
  
  else if( $ldap['bind'] )
    {
      $filter = "(sAMAccountName=" . $ldap['user'] . ")";
      $attr = array("memberof");
      $result = ldap_search($ldap['conn'],$ldap['dn'], $filter, $attr)
      or exit("Unable to search LDAP server");
      $entries = ldap_get_entries($ldap['conn'], $result);
      ldap_unbind($ldap);
  
      foreach($entries[0]['memberof'] as $grps) 
         {
           if (strpos($grps, $ldap_manager_group)) 
              { 
                 //redirect to Admin page
              }
  
           if (strpos($grps, $ldap_user_group)) 
              { 
                 //redirect to User page
              }
  }
  </code></pre>
  
  <p>I'm really lost as I have no idea what must be causing this error.</p>