1

In our system for some reason, we have deleted user with 0 uid. But for now I have to store some information in session for anonymous users. But Drupal is not allowing me to save the information in session.

Can someone suggest another way around?

I am trying

session_start();

$_SESSION['some_param'] = 'value';

for retrieving

session_start();

echo $_SESSION['some_param'];

But the values are not available after reload.

PS: It is working fine if I create a user with uid=0. But I need solution without uid=0.

4
  • I think, all anonymous users share uid = 0 Sep 14, 2015 at 7:07
  • 1
    Why have you deleted user 0?
    – Clive
    Sep 14, 2015 at 7:49
  • "we have deleted user with 0 uid" - this uid is always used for anon. Never delete anything with uid 0 or uid 1 unless you understand and altered inner workings of Drupal.
    – Mołot
    Sep 14, 2015 at 8:57
  • You will run into many problems without user zero. Whatever requirement you have for deleting user zero should be addressed in some other way.
    – rooby
    Sep 14, 2015 at 8:59

1 Answer 1

2

If you "have to store some information in session for anonymous users", then you will have to make uid=0 available to Drupal. Because that's the uid that Drupal always uses for anonymous users.

So you'll have to re-create that user with uid=0 (again) if you want this to work. If you would combine this with not granting any permissions to role anonymous, there is not a lot that anybody can do in your site if they are not logged in (apart from things like performing login). Maybe an acceptable work around?

About your "for some reason we have deleted user with id=0": it might be that the user with id=0 never got created before (so that it was never deleted). E.g. if the database of your site was created via some type of database copy (backup and restore) from a dev site to a prod site (using PhpMyAdmin). Forgot the exact scenario, but I've ran in such sites before, which caused problems for anonymous users (which is how we discovered such cases). The solution we used was to simply use PhpMyAdmin, and insert the user with uid=0 in the Drupal database (using PhpMyAdmin).

Your Answer

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

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