Hi,
Wednesday, February 12, 2003, 11:32:54 PM, you wrote:
RM> Any information would definitely be interesting.
here it is:
<?php
class msession_class{
var $ses; //session on flag
var $sessionname; //current name of session
var $message; //error message holder
var $modulename; //type of module, should be user
var $sessionid; //
var $sessionlife; //how long inactive before the session should
time out
var $host; //client host
var $Username; //username
function msession_class($sessionname="",$lifetime="",$maxgc="",$sessionid=''){
global $class_ref; //a reference array for access by
buried functions
$class_ref["msession_class"] =& $this;
ini_set( "session.save_handler", "user" );
function open($save_path, $session_name) {
return msession_connect('localhost','8086');
}
function close() {
msession_disconnect();
return true;
}
function read($key) {
$sessiondata = "";
$x = msession_ctl($key,'TTL');
if(!empty($x) && $x < 0):
msession_destroy($key); //session timed out so nuke
else:
$sessiondata = msession_get_data($key);
endif;
return $sessiondata;
}
function write($key, $val) {
global $class_ref;
msession_set_data($key,$val);
msession_timeout($key,
$class_ref['msession_class']->sessionlife);
return true;
}
function destroy($key) {
global $class_ref;
$result = msession_destroy($key);
$class_ref["msession_class"]->ses = 0;
$class_ref["msession_class"]->sessionid = "";
return $result;
}
function gc($maxlifetime) {
return true;
}
session_set_save_handler("open", "close", "read", "write", "destroy",
"gc");
//set up some defaults
$this->sessionname = $sessionname;
$this->sessionlife = $lifetime;
if($this->sessionname == ""):
$this->sessionname = "PHPSESSID";
endif;
session_name($this->sessionname);
if($lifetime == ""):
$this->sessionlife = get_cfg_var("session.gc_maxlifetime");
endif;
if(!empty($sessionid)){
session_id($sessionid);
}
//ok go for it
session_start();
$this->modulename = session_module_name();
$this->sessionid = session_id();
$this->ses = 1;
}
//oddball functions
function session_restart(){
session_destroy();
$url = "http://".$_SERVER["HTTP_HOST"];//.$_SERVER["PHP_SELF"];
header("Location: $url");
exit;
}
function addmessage($mess){
$this->message .= $mess;
}
function getmessage(){
return $this->message;
}
function getmodulename(){
return $this->modulename;
}
function getid(){
return $this->sessionid;
}
function getlifetime(){
return $this->sessionlife;
}
function setuser($host,$user){
$this->host = $host;
$this->Username = $user;
}
function getuser($type = ""){
if($type == "u"):
return $this->Username;
elseif($type == "h"):
return $this->host;
else:
return $this->host." ".$this->Username;
endif;
}
}
?>
usage
$session = new msession_class('SESSION_NAME');
It could be pruned down (get rid of junk functions :) and put into an auto prepend
file with the correct host
info for connecting, that way it would be transparent to your users.
I did my own class as the standard session stuff does not check for expired
data and msession has a simple method for checking this.
--
regards,
Tom
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php