Hi,

Wednesday, January 22, 2003, 6:34:45 PM, you wrote:
TR> Hi,

TR> Wednesday, January 22, 2003, 6:15:36 PM, you wrote:
HJ>> Hello, there.

HJ>> I'm Looking for 'Mohawk Software session handler functions' examples.

HJ>> PHP Manual describes it http://www.php.net/manual/en/ref.msession.php .

HJ>> But, There are no descriptions and examples.

HJ>> Anybody has one?

HJ>> Thanks in advanced answer!

HJ>> ##########################
HJ>> Heo, Jungsu Mr.

HJ>> SimpleX Internet. http://www.simplexi.com

TR> here is a class I made for msession it may give you some pointers :)

TR> <?php
TR> class msession_class{
TR>         var $ses;                                               //session on flag
TR>         var $sessionname;               //current name of session
TR>         var $message;                           //error message holder
TR>         var $modulename;                //type of module, should be user
TR>         var $sessionid;                 //
TR>         var $sessionlife;               //how long inactive before the session 
should time out
TR>         var $host;                                      //client host
TR>         var $Username;                  //username
TR>         function 
msession_class($sessionname="",$lifetime="",$maxgc="",$sessionid=''){
TR>                 global $class_ref;              //a reference array for access by 
buried functions
TR>                 $class_ref["msession_class"] =& $this;
TR>                 ini_set( "session.save_handler", "user" ); 
TR>                 function open($save_path, $session_name) {
TR>                         return msession_connect('localhost','8086');
TR>                 }
TR>                 function close() {
TR>                         msession_disconnect();
TR>                         return true;
TR>                 }
TR>                 function read($key) {
TR>                         $sessiondata = "";
TR>                         //This bit won't work on standard msession install it 
checks for a timed out session
TR>                         //$x = msession_ctl($key,'TTL');
TR>                         //if(!empty($x) && $x < 0):
TR>                         //      msession_destroy($key);
TR>                         //else:
TR>                                 $sessiondata = msession_get_data($key);
TR>                         //endif;
TR>                         return $sessiondata;
TR>                 }
TR>                 function write($key, $val) {
TR>                         global $class_ref;
TR>                         msession_set_data($key,$val);
TR>                         msession_timeout($key, 
$class_ref['msession_class']->sessionlife);
TR>                         return true;
TR>                 }
TR>                 function destroy($key) {
TR>                         global $class_ref;
TR>                         $result = msession_destroy($key);
TR>                         $class_ref["msession_class"]->ses = 0;
TR>                         $class_ref["msession_class"]->sessionid = "";
TR>                         return $result;
TR>                 }
TR>                 function gc($maxlifetime) {
TR>                         return true;
TR>                 }
TR>                 session_set_save_handler("open", "close", "read", "write", 
"destroy", "gc");
TR>                 //set up some defaults
TR>                 $this->sessionname = $sessionname;
TR>                 $this->sessionlife = $lifetime;
TR>                 if($this->sessionname == ""):
TR>                         $this->sessionname = "PHPSESSID";
TR>                 endif;
TR>                 session_name($this->sessionname);
TR>                 if($lifetime == ""):
TR>                         $this->sessionlife = get_cfg_var("session.gc_maxlifetime");
TR>                 endif;
TR>                 if(!empty($sessionid)){
TR>                         session_id($sessionid);
TR>                 }
TR>                 //ok go for it
TR>                 session_start();
TR>                 $this->modulename = session_module_name();
TR>                 $this->sessionid = session_id();
TR>                 $this->ses = 1;
TR>         }
TR>         //oddball functions
TR>         function session_restart(){
TR>                 session_destroy();
TR>                 $url = "http://".$_SERVER["HTTP_HOST"];//.$_SERVER["PHP_SELF";];
TR>                 header("Location: $url"); 
TR>                 exit;
TR>         }
TR>         function addmessage($mess){
TR>                 $this->message .= $mess;
TR>         }
TR>         function getmessage(){
TR>                 return $this->message;
TR>         }
TR>         function getmodulename(){
TR>                 return $this->modulename;
TR>         }
TR>         function getid(){
TR>                 return $this->sessionid;
TR>         }
TR>         function getlifetime(){
TR>                 return $this->sessionlife;
TR>         }
TR>         function setuser($host,$user){
TR>                 $this->host = $host;
TR>                 $this->Username = $user;
TR>         }
TR>         function getuser($type = ""){
TR>                 if($type == "u"):
TR>                         return $this->Username;
TR>                 elseif($type == "h"):
TR>                         return $this->host;
TR>                 else:
TR>                         return $this->host." ".$this->Username;
TR>                 endif;
TR>         }
TR> }
?>>

TR> usage
TR> <?
TR> include_once('msession_class.inc');
TR> $ms = new msession_class('TESTSESSION');
TR> ..thats it

TR> if you want to force it to use the same session from another server/domain with
TR> session_id set to the session you want start like this:

TR> include_once('msession_class.inc');
TR> $sessionid = '';
TR> if(isset($_REQUEST['session_id'])){
TR>         $sessionid = $_REQUEST['session_id'];
TR> }
TR> $ms = new msession_class('TESTSESSION','','',$sessionid);

TR> -- 
TR> regards,
TR> Tom

Actuall you can uncomment the read section check as that function has been added
to the latest php msession.c :)

function read($key) {
         $sessiondata = "";
         $x = msession_ctl($key,'TTL');
         if(!empty($x) && $x < 0): // negative value means session timed out
                       msession_destroy($key);
         else:
              $sessiondata = msession_get_data($key);
         endif;
         return $sessiondata;
}

-- 
regards,
Tom


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

Reply via email to