Hi,

I am using a search page for which i need to set some session variables in order to conduct search. The search form is positioned into a block. I can get correct search result when i am logged in, but when searching as anonymous user, i get wrong results as for anonymous users i am not getting the session values.

How can i get session variable values as anonymous user.
Please help.

Thanks in advance
Rizwana

Comments

vasi1186’s picture

Hi,

you should be able to use sessions also for anonymous users. Are you sure that you do not use some hack, or some speed boosters that make convert your sessions into lazy sessions (that are initiated only on user login)?

Vasi.

rrizia’s picture

Hi
thanks for ur reply. I am not sure what u mean by hack or speed booster. But my problem is my module stores the search criteria in session variables. This is done for pagination. Like when i go to the second page i need to send the search criteria again to the server and this was done by session variables.

But when i come to the function that fetches result for 2nd page or others i can see that i lost all the session variables i previously created while i submitted the search form for the first time and i get only the latest session variables that i save for in this current request for second page. I tried by printing the $_SESSION and found all the previous session variables missing. And it happened only for anonymous users not logged in users.

For example:
my search keyword is 'test'. When i submit the search form, i saved this keyword in a session variable as, $_SESSION['search_text'] = 'test';
Now say i got results that requires 2 pages. Then when i click on the second page i go back to server for the result and found no session variable as $_SESSION['search_text']. as a result blank search returns default values for the rest of the pages.

Can anyone help why it happened for anonymous users???

Thanks in advance
Rizwana.

rrizia’s picture

hi again,

i just figured out what was causing the problem. In order to access session data for anonymous users the 'Users' table in the drupal database must contain a user with uid = 0. I found that in my database somehow the user entry with uid = 0 got modified and that is what was causing the problem.

cr0ss’s picture

Thanks a lot for this solution. Ive bit an hours fighting with it.

artemshymko.com

Hammad83’s picture

I was stucked, but ur comment save me :)
Thanks

jiml09’s picture

I have a uid = 0 in my Users table and I am still having the problem. Does anyone know what else might be causing it?

aks_richa’s picture

thank you so much.... you saved my time... i also got the same problem.........

johnhorning’s picture

In addition to having a user 0 in the database, the user's status must be set to 1.