Posted by jromine on June 16, 2010 at 6:23pm
I'm writing a module and looking to save some user preferences in the user's session. The settings would not need (or want) to persist after logout. I looked, but didn't find a Drupal API for this. Is there an API or convention for how to do this (and not conflict with another module)?

Comments
Session API
After more searching, I found:
John Romine
$_SESSION is a perfectly fine solution
$_SESSION is a perfectly fine solution. Drupal stores a user's $_SESSION variable and session id in the sessions table, and then also stores the session id in a cookie. Any time that user returns, the session id in the cookie is used to load $_SESSION from the database. $_SESSION is also nice because you can easily read and write to it just by assigning variables, so you don't have to worry about things like set_cookie() when you're dealing with cookies.
If you want to avoid conflicts with other modules, you could namespace your variables like $_SESSION['mymodule_variable1'] (or $_SESSION['mymodule']['variable1'] but the first way is probably closer to Drupal's style).
Edit: Forgot to mention, session will also work for anonymous users if you need that. As long as the visitor's cookie stays around, their session will be persisted.