title: ldap auth with php fails intermittently
body: <p>I have put together a basic web-app, the actual web-app itself works fine. However I wanted to add user authentication using our existing ldap server. The ldap script seems to work intermittently though, when logging in the first few attempts will fail with the 'access denied' message then it will authenticate. I ran the script stand alone without the app and the same behavior applies.   </p>
  
  <p>I cant seem to tie the problem down anywhere, I can only assume it is occuring on the ldap side and not the php side. I have included the script below, any help would be great.</p>
  
  <p>While writing this, it failed to auth 3 times and passed twice...</p>
  
  <pre><code>&lt;?php
  
  $user = $_POST['login-name'];
  $password = $_POST['login-pass'];
  
  $ldap_user = 'uid='.$user.',ou=people,dc=ourdomain,dc=com,dc=au';
  $ldap_pwd = $password;
  
  $ldaphost = 'ldap://ldapserver.domain.com';
  $ldapport = 389;
  
  $ds = ldap_connect($ldaphost, $ldapport)
  or die("Could not connect to $ldaphost");
  if ($ds)
  {
      $username = $ldap_user;
      $upasswd = $password;
  
      $ldapbind = ldap_bind($ds, $username, $upasswd);
  
  
      if ($ldapbind)
          {
              //print "Congratulations! $username is authenticated.";
              header('Location: message.html');
          }
      else
          {print "Access Denied!";}
  
  
  }
  ?&gt;
  </code></pre>