title: Store LDAP connection and bind in session
body: <p>I've written an application where users are authenticated and logged in through LDAP. This works really well, I just do an <code>ldap_bind()</code> with their credentials, and if it's true then authenticate them - otherwise, tell them to sling it. I can keep their username in a session variable so I know who they are. </p>
  
  <p>Now, a part of the application requires the users to search LDAP to find other users. I've used <a href="http://code.google.com/p/jquery-autocomplete/" rel="nofollow"><code>jquery-autocomplete</code></a> and <a href="http://php.net/manual/en/function.ldap-search.php" rel="nofollow"><code>ldap_search()</code></a> to implement this, and it works really well - users just type in the username, first name or surname, and all the possible matches are suggested. Lovely :) </p>
  
  <p>However, corporate IT does not even allow anonymous browsing of the directory within the network, so, right now, I'm storing the username and password in <code>$_SESSION</code> so that I can do a new bind each time the autocomplete script is called.  I know it's <em>fairly</em> secure, and the tool is only internal, but this feels like something I shouldn't really do, and definitely wouldn't do if it was being let "out into the wild". </p>
  
  <p>What I'd like to do is create the bind to LDAP when they log in, and then somehow have this authentication remembered across the session, so we can do as many searches as we need to without having to re-authenticate each time. I've got no access to the server, so I can't change anything on there. Can I somehow store the successful bind in <code>$_SESSION</code> and reuse it? </p>
  
  <p>If this isn't relatively straightforward, does anyone have any other suggestions as to how this could be implemented?</p>