How to save a session variable in drupal 7?
drupal, drupal-7, php, session-variables
Solution
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");
Problem
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.