In drupal, how do you store/read session variables? Also, how can i access a stored session variable through javascript?

I'm trying to store whether if a user has closed my modal or not so it doesn't pop up for another day.

1 Answer 1


Accessing a session variable in Drupal is not different from how it is done with plain PHP: with $_SESSION.

As for reading them with JavaScript, it is enough to use code similar to the following one.

// PHP
drupal_add_js(array('myModule' => array('key' => $_SESSION['key'])), 'setting');
// JavaScript
key = Drupal.settings.myModule.key;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.