title: Find username with LDAP
body: <p>I maintain an intranet web site for a large company. Since a failure of current user authentication system, I had to develop an urgent solution.
  Here is the simplified code</p>
  
  <pre><code>$usr=$_POST['user'];
  $psw=$_POST['code'];
  
  if(!strlen($psw) )
  $psw="x";
  // because empty password works fine for any user
  
  $ldap= ldap_connect("LDAP://ldapserver.xxx.local");
  if(!$ldap)
  exit(0);
  
  ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  ldap_set_option($ldap, LDAP_OPT_OPT_REFERRALS, 0);
  
  if($bind = @ldap_bind($ldap, $usr, $psw){
  header("Location: http:10.xx.xx.xx/entrance.php?id=$usr");
  // login OK, look for user privileges
  }else{
  header("Location: http:10.xx.xx.xx/login.php?INV=1");
  // back to login page
  }
  </code></pre>
  
  <p>The code works just fine, but I don't want users have to enter their network user name and password,
  when a user comes to this page, connect and bind anonymously to LDAP server, could a page get information about username of this user.</p>
  
  <p>And it would be a great bonus if it could give, some extra info such as full name, branch code, branch, mail addr ..   etc</p>