note 56172 modified in function.session-set-save-handler by danbrown
| From: | danbrown@php.net | Date: | Sun, 23 Jan 2011 16:18:51 +0000 |
| Subject: | note 56172 modified in function.session-set-save-handler by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176045@lists.php.net to get a copy of this message | ||
When creating a session-handling class, I have discovered that it is important to remember that your
session object and the $_SESSION global are TWO SEPARATE ENTITIES. You need to create a reference
between your Session Object and the built-in $_SESSION global:
<?php
session_set_save_handler(
array(&$this, "_OPEN"),
array(&$this, "_CLOSE"),
array(&$this, "_READ"),
array(&$this, "_WRITE"),
array(&$this, "_DESTROY"),
array(&$this, "_GC")
);
session_start();
header("Cache-control: private"); // to overcome/fix a bug in IE 6.x
$this->session =& $_SESSION;
?>
Additionally, when you add a $_SESSION variable, it's a good idea to add it as a Session Object
variable at the same time, if you want your code to use the Session Object between page
changes/reloads:
<?php
function setSessionVariable($key,$value) {
$_SESSION[$key] = $value;
$this->session[$key] = $value;
return;
}
?>
--was--
When creating a session-handling class, I have discovered that it is important to remember that your
session object and the $_SESSION global are TWO SEPARATE ENTITIES. You need to create a reference
between your Session Object and the built-in $_SESSION global:
session_set_save_handler(
array(&$this, "_OPEN"),
array(&$this, "_CLOSE"),
array(&$this, "_READ"),
array(&$this, "_WRITE"),
array(&$this, "_DESTROY"),
array(&$this, "_GC")
);
session_start();
header("Cache-control: private"); // to overcome/fix a bug in IE 6.x
$this->session =& $_SESSION;
Additionally, when you add a $_SESSION variable, it's a good idea to add it as a Session Object
variable at the same time, if you want your code to use the Session Object between page
changes/reloads:
function setSessionVariable($key,$value) {
$_SESSION[$key] = $value;
$this->session[$key] = $value;
return;
}
http://php.net/manual/en/function.session-set-save-handler.php