From: max
Date: Mon Jan 29 10:07:50 2001
Modified files:
php-lib/php/session/session4_custom.inc
Log message:
Changed a lot.
Made some stuff clean.
Added support for native PHP4 storage containers: a new property 'module' is
taking 'user', 'files' or 'mm' value. If it is 'user', the custom CT_* container will
be used.
Otherwise - one of php's builtin containers ('files' by dafault)
Index: php-lib/php/session/session4_custom.inc
diff -u php-lib/php/session/session4_custom.inc:1.4
php-lib/php/session/session4_custom.inc:1.5
--- php-lib/php/session/session4_custom.inc:1.4 Thu Jan 11 14:46:35 2001
+++ php-lib/php/session/session4_custom.inc Mon Jan 29 10:07:48 2001
@@ -9,35 +9,40 @@
* some of the code taken from Teodor Cimpoesu's session4 class
* Copyright (c) 2000 Teodor Cimpoesu <[EMAIL PROTECTED]>
*
- * $Id: session4_custom.inc,v 1.4 2001/01/11 13:46:35 max Exp $
+ * $Id: session4_custom.inc,v 1.5 2001/01/29 09:07:48 max Exp $
*
*/
class Session {
var $class_name; ## Used here for comaptibility
+ var $id;
+ var $name;
+
var $auto_init = ''; ## Name of the autoinit-File, if any.
- var $secure_auto_init = 1; ## Set to 0 only, if all pages call
- var $in = false; ## Marker: Did we already include the autoinit
file?
+
+ var $cookie_path = '/';
+ var $cookiename;
+ var $lifetime = 0;
var $cookie_domain = ''; ## If set, the domain for which the
## session cookie is set.
- var $magic = ""; ## Some string you should change.
- var $cookiename;
var $allowcache = "passive"; ## "passive", "no", "private", "public"
var $allowcache_expire = 1440; ## If you allowcache, data expires in this
## many minutes.
- var $lifetime = 0;
- var $gc_time = 1440; ## Purge all session data older than 1440
minutes.
+ var $module = "user"; // session storage module - user, files
+or mm
+ var $save_path; // where to save session files if module == files
var $that_class = ""; ## Name of data storage container
var $that;
+
+ var $gc_time = 1440; ## Purge all session data older than 1440
+minutes.
- var $id;
- var $name;
// compatibility properties
- var $mode;
var $fallback_mode;
var $gc_probability; ## set this in php.ini or httpd.conf (.htaccess)
+ var $secure_auto_init = 1; ## Set to 0 only, if all pages call
+ var $in = false; ## Marker: Did we already include the autoinit
+file?
+ var $magic = ""; ## Some string you should change.
@@ -69,25 +74,8 @@
function get_id() {
-
- $newid = false;
$id = session_id();
- if (!$id) {
- $newid = true;
- $id = $this->that->ac_newid(md5(uniqid($this->magic)), $this->name);
- session_id ($id);
- }
$this->id = $id;
-
-
- if (get_cfg_var ('session.use_cookies') == 1) {
- if ($newid && !$this->lifetime) {
- setcookie ($this->name, $this->id, 0, "/", $this->cookie_domain);
- }
- if ($this->lifetime > 0) {
- setcookie ($rhis->name, $this->id, time()+$this->lifetime*60, "/",
$this->cookie_domain);
- }
- }
}
/**
@@ -226,9 +214,9 @@
function start() {
$this->set_container();
$this->set_tokenname();
- if (!$this->cookie_domain) $this->cookie_domain = get_cfg_var
("session.cookie_domain");
$this->put_headers();
- session_start();
+ @session_start();
+ if ($this->module != 'user') $this->get_id(); // otherwise get_id() is called in
+custom open() method
}
function open() {
@@ -237,7 +225,7 @@
}
function close() {
- return true();
+ return true;
}
@@ -245,8 +233,11 @@
* delete the current session destroying all registered data
*/
function delete () {
- $this->that->ac_delete($this->id, $this->name);
- $this->put_id();
+ if ($this->module == 'user') {
+ $this->that->ac_delete($this->id, $this->name);
+ $this->put_id();
+ return true;
+ }
return true;
}
@@ -256,52 +247,89 @@
a database table
*/
function freeze () {
- $str = session_encode();
- $r = $this->that->ac_store($this->id, $this->name, $str);
-#$this->release_lock();
- return $r;
+ if ($this->module == 'user') {
+ $str = session_encode();
+ $r = $this->that->ac_store($this->id, $this->name, $str);
+ #$this->release_lock();
+ return $r;
+ }
+ return true;
}
/* thaw():
get frozen session vars
*/
function thaw() {
-# $this->get_lock();
- $vals = $this->that->ac_get_value($this->id, $this->name);
- return $vals;
+ if ($this->module == 'user') {
+ # $this->get_lock();
+ $vals = $this->that->ac_get_value($this->id, $this->name);
+ return $vals;
+ }
+ return true;
}
/* Garbage collection
Destroy all session data older than $this->gc_time
*/
function gc() {
- if (!$this->gc_time ) $this->gc_time = get_cfg_var("session.gc_maxlifetime");
- return $this->that->ac_gc($this->gc_time, $this->name);
+ if ($this->module == 'user') {
+ if (!$this->gc_time ) $this->gc_time = get_cfg_var("session.gc_maxlifetime");
+ return $this->that->ac_gc($this->gc_time, $this->name);
+ }
+ return true;
}
// helper functions used in initialization
function set_container(){
- //global $sess;
-
- $name = $this->that_class;
- $this->that = new $name;
+ switch ($this->module) {
+ case "user" :
+ session_module_name('user');
+ $name = $this->that_class;
+ $this->that = new $name;
- $this->that->ac_start();
- // set custom session handlers
- session_set_save_handler(array (&$this, 'open'),
- array (&$this, 'close'),
- array (&$this, 'thaw'),
- array (&$this, 'freeze'),
- array (&$this, 'delete'),
- array (&$this, 'gc')
- );
+ $this->that->ac_start();
+ // set custom session handlers
+ session_set_save_handler(array (&$this, 'open'),
+ array (&$this, 'close'),
+ array (&$this, 'thaw'),
+ array (&$this, 'freeze'),
+ array (&$this, 'delete'),
+ array (&$this, 'gc')
+ );
+ break;
+ case "mm":
+ session_module_name('mm');
+ break;
+ case "files" :
+ default:
+ if ($this->save_path) session_save_path($this->save_path);
+ session_module_name('files');
+ break;
+ }
}
function set_tokenname(){
- $this->name = ($this->cookiename=="") ? $this->classname : $this->cookiename;
- session_name ($this->name);
+ $this->name = ($this->cookiename=="") ? $this->classname : $this->cookiename;
+ session_name ($this->name);
+
+ if (!$this->cookie_domain) {
+ $this->cookie_domain = get_cfg_var ("session.cookie_domain");
+ }
+
+ if (!$this->cookie_path && get_cfg_var('session.cookie_path')) {
+ $this->cookie_path = get_cfg_var('session.cookie_path');
+ }
+ elseif (!$this->cookie_path) {
+ $this->cookie_path = "/";
+ }
+
+ if ($this->lifetime > 0) {
+ $lifetime = time()+$this->lifetime*60;
+ }
+ else $lifetime = 0;
+ session_set_cookie_params($lifetime, $this->cookie_path, $this->cookie_domain);
}
function put_headers() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]