i would like use a variable session ($_session) but it doesn't work in Drupal 7. What are the possibilities in Drupal 7 in order to save variable session.
You can try this.
function lists_session($key, $value = NULL) {
static $storage;
if ($value) {
$storage[$key] = $value ;
$_SESSION['lists'][$key] = $value ; // I use 'lists' in case some other module uses 'type' in $_SESSION
}
else if (empty($storage[$key]) && isset($_SESSION['lists'][$key])) {
$storage[$key] = $_SESSION['lists'][$key];
}
return $storage[$key];
}
So, to save a variable in Session:
lists_session("s_key", "value");
And to retrieve the value, just use:
$myVar = lists_session("s_key");
I have no problem of using the $_SESSION variable in my own module. Just keep in mind to create a unique sub key for your data.
$_SESSION['mydata'] = array(of your data);
Remember to serialise your data such as array, obj... before save to session. $arr = array(); $_SESSION['mysession'] = serialise($arr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With