Is it possible to connect to an LDAP server with ldap_connect() then
store the resulting resource handle in the session variable $SESSION[]? 
I'm hoping to avoid re-connecting and re-binding every time the user
clicks on something.

It does not appear to be saving my LDAP connection handle along with
the other $SESSION variables I'm successfully storing.

The relevant code fragments in execution order are from an
Authentication function:

  session_start();

  $ldapConn = ldap_connect($confLdapServer)
      or die("Cannot connect to LDAP server=$confLdapServer");
  ldap_bind($ldapConn, $ldapDN, $password)
       or die("Could not do authenticated bind to LDAP server='$confLdapServer'"
             ." with password='$password' and dn='$ldapDN'");

  $_SESSION['username']         = $username;
  $_SESSION['ldapConn']         = $ldapConn;
  $_SESSION['ldapDN']           = $ldapDN;

When I return to the page after authenticating $_SESSION['ldapConn']
is zero.  The other session variables are fine.  

I can see them in the session serialized under tmp: 

  ...  ldapConn|i:0; ...


Oops, I didn't see this bit the first 37 times I read the manual on
Sessions, I only looked at the top level "Session handling functions";
I just noticed the following buried under session_register():

  http://us3.php.net/function.session-register

  Note: It is currently impossible to register resource variables in a
  session. For example, you cannot create a connection to a database
  and store the connection id as a session variable and expect the
  connection to still be valid the next time the session is restored.

  PHP functions that return a resource are identified by having a
  return type of resource in their function definition. A list of
  functions that return resources are available in the resource types
  appendix.

That appendix explicitly lists ldap_connect()'s resource handle.  

So it sounds like I have to ldap_connect() and ldap_bind() every time
the user clicks on my PHP app.  Ouch.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to