By lukas.fischer on
Dear all
I'm just developing an order-module. Everything works fine as registered user, they can start adding orders (adding items to the session). But as anonymous user's the session data is not stored. Why?
I also don't find any information about this.
Can you help?
Thank you,
Lukas
Comments
I recently encountered the
I recently encountered the same problem...
http://books.google.ca/books?id=aWYOGXQShegC&pg=PA254&lpg=PA254&dq=anony...
Read the "caution" paragraph.
Can you store the data in cookies?
---
Yuriy Babenko
www.yubastudios.com
---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com
But this means, that I
But this means, that I cannot store any information for an anonymous user to the session?
What if I do want to store session information and I don't care about crawlers and robots?
How can I enable storing session data for anonymous user?
Thanks
Lukas
I just found this in the
I just found this in the source doc of sess_write
// Only save session data when when the browser sends a cookie. This keeps
// crawlers out of session table. This reduces memory and server load,
// and gives more useful statistics. We can't eliminate anonymous session
// table rows without breaking throttle module and "Who's Online" block.
So, crawlers do not send a cookie and that's why no anonymous session is created.
But my session is still not saved ... :-(
It's strange, when I do set the session variable on one page, everything works fine. It's saved in the session table. When I go to the next page, drupal finds the correct session, but then it overwrites the session.
See:
First page:
0.53 0 sess_write SELECT sid FROM sessions WHERE sid = 'f98eb36bce4124d86b911e9280661a75'
0.61 0 sess_write UPDATE sessions SET uid = 0, cache = 0, hostname = '80.218.113.66', session = 'warenkorb|a:1:{s:5:\"items\";a:1:{s:13:\"7640138940132\";a:2:{s:12:\"field_anzahl\";i:1;s:9:\"field_ean\";s:13:\"7640138940132\";}}}', timestamp = 1215865627 WHERE sid = 'f98eb36bce4124d86b911e9280661a75'
session saved correctly, then I load another page ...
Second page:
0.49 0 sess_write SELECT sid FROM sessions WHERE sid = 'f98eb36bce4124d86b911e9280661a75'
0.48 0 sess_write UPDATE sessions SET uid = 0, cache = 0, hostname = '80.218.113.66', session = '', timestamp = 1215865665 WHERE sid = 'f98eb36bce4124d86b911e9280661a75'
session is empty :-(
I even couldn't find what function called sess_write to check where the parameter comes from and how it looks like.
If somebody can give me a hint, that would be great! I'm just investing hours to solve this session problem and I'm almost distressed...
Thanks
Lukas
is it possible that
is it possible that localizer makes problems?
Have the same problem, i
Have the same problem, i need to store anonimous user choice of currencies. Also tried to use session but works only for registered users.
I've created function like this to check that session for unregistered user is created:
and get the result on the page like that:
87n3ikn17h1e7gvpu860fo2gf3 0
SESS31191995e555b6daa783fdec1e71cfa6
87n3ikn17h1e7gvpu860fo2gf3
0
us
So as you see the session was created properly, and variable is set, but it is not stored, because on another page I printed $_SESSION['choosen_valuta'] and got empty result.
I had no localizer installed.
...
Make sure the {users} table contains a row for UID #0, or else Drupal will fail to load this user's saved session.
Thanks moofie! You are right
Thanks moofie!
You are right about {users} table - i deleted(and forgot about it) the row with uid=0 from it, but i had to do it because the database didn't want to install after backup - allways gave error "duplicate entry". That's because of, as i thought, column uid has autoincrement property and is primary key for this table. And after deleting the row from table database installed smoothly.
But now how can I create this row back and is this the cause? I looked into the code of sess_write() function, which i think is responsible for storing datas and hadn't found inner join for table session with users when uid=0 was used or something like that - here the code from that function:
So what am I to do now and can anybody explain WHY the session is not stored?
...
Use phpMyAdmin, or in some appropriate place type:
(In other words, all columns should have their default DB values, and 'uid' should be '0'.)
But sess_read() has inner join. That's why I wrote "will fail to load this user's saved session".
did as you sad INSERT INTO
did as you sad INSERT INTO users (uid) values (0); but it just added the row with uid=32 not 0 because I allready have admin user with uid=1 and editor with uid=2 etc. and column uid is autoincremented.
...
So do "update users set uid=0 where uid=32;", or edit that row using phpMyAdmin.
Thanks again, moofie, this
Thanks again, moofie, this worked.
Now I will check my session!
Everything is working,
Everything is working, session is stored and is read from the database now as it should in drupal, starting from second visit.
If someone needs to store info about first visit of user to your site and do not loose data when user becomes authorized and new session is created for him see kaiserjozy tutorial here:
http://drupal.org/node/344089
Tried to do as you sad,
Looked into the table sessions and the value is stored there, so You was absolutely right, moofie about sess_read() and inner_join! So how to insert the row for uid=0 into users table. column uid is autoincremented and refuses to insert such row. May be I need to alter column properties before to insert and after inserting row set the property autoincrement back?
PS: did just as moofie proposed, just updated the row and it worked!
I'm writing a howto ...
I'm writing a howto on how I circumvented this issue. Wasn't as easy as I thought.
I needed to track users and for shopping cart reason and ad tracking, I couldn't save anonymous user data.
Stay tuned...
Howto is published
goto http://drupal.org/node/344089 for all the details
Question is ambiguous ...
What do you mean there is no session for anonymous users?
PHP session is opened for even for anonymous users. Well one more thing PHP session is nothing but session cookie.
For example in bootstrap.inc
See line 987
You can store the session information of the anonymous users in PHP sessions.
For example:
$_SESSION['var1'] = "hello"; and so on...
Let me know if it makes sense ...
Thanks,
Vamsee
You go try to do it for
You go try to do it for anonimous user - and see, I did it just as explained above in http://drupal.org/node/281447#comment-1143368 and the next visit of that user session was empty again.
My problem was solved with the help of moofie, see http://drupal.org/node/281447#comment-1146721
Pressflow issue
As we know if we install Pressflow version of Drupal it removes the row with uid=0. Is it fine if we add the row with uid=0 in table in this case?