How to maintain a variable between IMP pages (sessions?).

Santiago Romero sromero@servicom2000.com
Fri, 13 Jul 2001 08:10:15 +0200


 Hi!

 How is possible to maintain a PHP variable defined on a PHP3 file
 (IMP 2.2.5, mailbox.php3) so that is available for another PHP3
 file (compose.php3) and for future reloads of mailbox.php3?

 I have a variable called can_use_attachs (can_use_attachs) that
 is checked on an LDAP server on mailbox.php3 and used on compose.php3.
 The idea is just to check the LDAP server just once (the first
 time) and set that variable so that future reloads do not check the
 ldap server another time.

 I'm using the following code, but I suspect that produces a segmen-
 tation fault one time each about 4000 reloads (yes, I can reload
 the page thousands of times automatically, and when I reach about
 4000 it produces a segmentation fault on token_cache.c):

// the beginning of my mailbox.php3 file
if( !isset( $can_use_attachs ) )
{
 $ds=ldap_connect("192.168.1.152");

 if ($ds)
 {
   $r=ldap_bind($ds);
   $busca="uid=" . $imp->user;
   $sr=ldap_search($ds,"cn=Correo,o=sistemas.servicom2000",
                   $busca);
   if( ldap_count_entries($ds,$sr) < 1 )
     SetCookie( "can_use_attachs", 'n', time()+3600 );
   else
   { 
     $info = ldap_get_entries($ds, $sr);
     if( $info[0]["roomnumber"][0] == "s" )
       SetCookie( "can_use_attachs", 's', time()+3600 );
     else
       SetCookie( "can_use_attachs", 'n', time()+3600 );
   }
   ldap_close($ds);
 }
}

 And in compose.php3:

<? if( $can_use_attachs == 's' ) { ?>

 <input type="hidden" name="attachmentAction" value="">
 (etc...)
 <?php endif; ?>

<?php } ?>
 

 Does anyone know a better way of doing the above? I don't know how
 to use PHP sessions (as used on Horde/IMP) so that I don't need
 cookies to set up that variable.
 
PS: and if someone can see in the above code what could be the 
cause of the segmentation fault, please tell me.

 CU and thanks a lot.

-- 
Santiago Romero
Departamento de Sistemas
sromero@servicom2000.com

Av. Primado Reig 189, entlo
46020 Valencia - Spain
Telf. (+34) 96 332 12 00
Fax. (+34) 96 332 12 01
http://www.servicom2000.com