Sessions and non-logged-in users
Hi everyone, I have to store some item id's (a little like a cart) for anon users. I can of course set a cookie with the id of the items, but i was wondering if there were any built in ways to manage this kind of thing? many thanks -- Nick Wilson http://performancing.com/user/1
Use session data. To store something use: $_SESSION['foo'] = $bar; To get it back use: $baz = $_SESSION['foo']; That is it. On 5/16/06, Nick Wilson <nick@communicontent.com> wrote:
Hi everyone,
I have to store some item id's (a little like a cart) for anon users. I can of course set a cookie with the id of the items, but i was wondering if there were any built in ways to manage this kind of thing?
many thanks -- Nick Wilson http://performancing.com/user/1
* and then Khalid B declared....
Use session data.
To store something use:
$_SESSION['foo'] = $bar;
To get it back use:
$baz = $_SESSION['foo'];
That is it.
Thanks. Will the data not be lost when the browser is closed? -- Nick Wilson http://performancing.com/user/1
* and then Khalid B declared....
Use session data.
To store something use:
$_SESSION['foo'] = $bar;
To get it back use:
$baz = $_SESSION['foo'];
That is it.
Thanks.
Will the data not be lost when the browser is closed?
No. Session data are stored in drupal's sessions table, and cross referenced with an SID that is stored in the PHPSESSID cookie on the user's machine. So, the data will be lost if that PHPSESSID cookie for the site is deleted.
* and then Khalid B declared....
Use session data.
To store something use:
$_SESSION['foo'] = $bar;
To get it back use:
$baz = $_SESSION['foo'];
That is it.
Thanks.
Will the data not be lost when the browser is closed?
The browser has a cookie with an ID that corresponds to a row in the sessions table, which is where $bar is stored. If the user has the browser set to erase cookies when the browser closes, then the answer to your question is yes, because Drupal cannot associate the row without the ID stored in the cookie. Else no.
* and then John VanDyk declared....
The browser has a cookie with an ID that corresponds to a row in the sessions table, which is where $bar is stored.
If the user has the browser set to erase cookies when the browser closes, then the answer to your question is yes, because Drupal cannot associate the row without the ID stored in the cookie. Else no.
Thanks makes sense. Ok thanks guys, this seems like a perfect solution. much obliged :) -- Nick Wilson http://performancing.com/user/1
participants (3)
-
John VanDyk -
Khalid B -
Nick Wilson