From: Jamie C. <jca...@we...> - 2003-10-09 00:20:26
|
Marius Popovici wrote: > Hi all, > I am currently working on a Webmin module and I was wondering if > there is session support in miniserv. I looked through the docs and i > couldn't find anything on the subject so if anyone knows something the > help would be appreciated. > > What i am trying to do is the following. I have some module > configuration properties that are frequently requested by many CGIs and > i want to avoid reading this stuff from a configuration file everytime > it is needed. Instead i want to create a ConfigurationProperties object > that is stored in the server's session so it can be accessed very > quickly. Webmin doesn't have any kind of automatic session object tracking like JSP scripts or servlets do, but you can get the current session ID from the $session_id global variable. This could then be used as a key to lookup an entry in a DBM or text file that your module maintains, to store extra information associated with the session. The code might look something like : dbmopen(%sessiondata, "$module_config_directory/sessiondata", 0700); # set_session_data(hashreference) sub set_session_data { $sessiondata{$session_id} = &serialize_variable($_[0]); } # get_session_data() # Returns a hash reference sub get_session_data { return &unserialise_variable($sessiondata{$session_id}); } Note the use of the serialize_variable and unserialise_variable standard functions to convert an arbitrary Perl hash to and from a string that can be safely stored in the DBM. - Jamie |