auto_init file included every page_view with session4
Brought to you by:
nhruby,
richardarcher
As noted in the source, sess->in does not persist so
the auto_init file is included every pageview.
Email discussion:
https://sourceforge.net/mailarchive/message.php?msg_id=3573511
Logged In: YES
user_id=694133
Here's a patch which addresses this problem (I was the one
who brought it to Joe Stewart's attention). Because php4
apparently won't allow an instance variable to be declared
global, and because a variable can't be placed under php4
session management unless it _is_ global, an intermediate
data structure must be used to preserve phplib session
instance variables throughout the session. I've created a
CurrentSession class which serves as such a container. This
may be overkill, but I considered it to be a more flexible
solution than a set of global variables whose names might be
best kept private, or a global array.
--- session4.inc 2003-01-21 23:44:05.000000000 -0600
+++ session4.inc.fixed 2003-01-21 23:44:00.000000000 -0600
@@ -11,6 +11,26 @@
* @access public
* @package PHPLib
*/
+
+class CurrentSession {
+ /**
+ * Include anything in this class that needs to be
preserved across page
+ * accesses and restored to $sess instance variables. The
class is
+ * instantiated in $this->start() and $sess instance
variables are copied
+ * to it in $this->freeze(). Code must be added in these
functions to do
+ * this.
+ */
+ var $ai_done = false; // storage for $sess->in
+
+ function set_ai_done($val) {
+ $this->ai_done = $val;
+ }
+
+ function get_ai_done() {
+ return $this->ai_done;
+ }
+}
+
class Session {
@@ -170,6 +190,15 @@
$ok = session_start();
$this->id = session_id();
+ $sob = "sob_".session_id();
+ global $$sob;
+ if (!isset($_SESSION["sob_".session_id()])) {
+ $$sob = new CurrentSession;
+ $this->register($sob);
+ }
+ // Get the auto_init flag
+ $$sob = $_SESSION[$sob];
+ $this->in = $$sob->get_ai_done();
// If register_globals is off -> restore session
variables to global scope
if(!(bool) ini_get('register_globals')) {
@@ -551,6 +580,11 @@
eval("\$_SESSION[\$key]= \$$key;");
}
}
+ // Save the auto_init flag
+ $sob = "sob_".session_id();
+ global $$sob;
+ $$sob = $_SESSION[$sob];
+ $$sob->set_ai_done($this->in);
}
/**