Cannot store ldap_connect() resource handle in session $SESSION[] ?

This is a discussion on Cannot store ldap_connect() resource handle in session $SESSION[] ? within the PHP General forums, part of the PHP Programming Forums category; Is it possible to connect to an LDAP server with ldap_connect() then store the resulting resource handle in the session ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-09-2003
Chris Shenton
 
Posts: n/a
Default Cannot store ldap_connect() resource handle in session $SESSION[] ?

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.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:28 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0