All Important User Zero

tags:

A while back, I came across a "duplicate entry" problem that resulted from a missing row in the drupal table 'users'.

It turns out that the users table is not the only one that requires information on "user 0" (aka "anonymous").

This week I came across another problem in which anonymous users get a "you are not authorized ..." message when trying to view any sort of content.

If you find yourself having trouble accessing cotent or using your site as an anonymous user, you can safely run the following queries against your Drupal DB (4.6/4.7):

INSERT INTO users (uid, name, mail) VALUES ('0', '', '');
INSERT INTO users_roles (uid, rid) VALUES (0, 1);
INSERT INTO node_access VALUES (0, 0, 'all', 1, 0, 0);

If any of the queries above returns a "duplicate entry" error, that means a row already exists, and that table is already OK.

This will fix the types of problems I mentioned above.

I'm not aware that Drupal itself can actually remove any of these rows. When they go missing, my assumption would be that someone has removed them.

This can be caused by a bug (fixed in CVS) in user deletion. When an admin deletes a user, accidentally goes back to the confirmation screen and confirms deleteion again, uid 0 is gone. The same happens when two admins try to delete a user at the same time.
do you know where the fix is for this? This problem seems to have happened to a ton of people, some of who gave up on their drupal sites because they couldn't fix it. John

I stepped through updating all of the three tables as listed, and am still getting no access to content whatsoever. Renamed installed modules directories to de-activate. Still troubleshooting.

Thanks for any input.

A corrupt or missing User 0 is not the only cause of access problems. Be sure to check out my tips on access problems page as well. Renaming module directories will not prevent Drupal from recognizing them. Drupal scans the entire modules folder for '.module' files. You must delete the folders or move them outside of the modules directory to prevent Drupal from including them.

I just wanted to add that I was getting "you are not authorized..." messages for *authenticated* users as well as anonymous users. Running the "node_access" insertion given above solved the problem. I can't say I understand why, but I'm happy nonetheless! BTW, I'm running Drupal 5.1.

We experienced the same issue - access denied errors for anonymous and authenticated users, but only on built-in content types (pages and stories). while we're still testing - this fix seems to work. THANK YOU so much - this problem was driving us insane.

Thank you, Thank you, Thank you!!!! I was getting "Access Denied" for all of my pages after I installed a new module, and no matter what I did, I couldn't access my Login page to be able to go in and disable the module. Running those 3 INSERT commands fixed it, and now I'm able to log in again. (In particular, it was the third insert -- the node_access one -- that did the trick.) Whew!!! Thanks so much!!! --Stephanie

Thank U :) The insert fixed my problem :).
the problem started after installing a new module

Hi Harry,

Great work!
For me the third insertion also did the job like with others who commented here.

Any idea why anonymous users are getting code like the instance below when they access (can access, thanks to your fix) random pages in the site?

a href="/user/login?destination=comment/reply/178%2523comment_form" Login /a or a href="/user/register?destination=comment/reply/178%2523comment_form">register /a to post comments

(< and > stripped because they produce log-in requests here :-)

Other users get the correct surface text.

Help much appreciated. Thank you so much.

Arnold

the "destination" parameter tells drupal what page to send the user to after he has logged in.

Thanks. But... there shouldn't code on the page.
Any advice on how to get rid of it?
Arnold

You would need to override theme_comment_post_forbidden() in your template.php file. But there is really no reason to do this. If a user is logging in so that he can post a comment, it makes perfect sense to take him back to the thread he wants to comment on after he logs in.

My hero!

Took me hours of fiddling before I had the good sense and let Google guide me here. Fixed!

Thanks a million, Niels.

My hero too!
And this is a fresh drupal6.10 installation!!

One of the grate information you provide.Thanks i am going to try this

I want to thank you for this post. I had no idea that the user 0 is for anonymous users.. duuu... I am learning, and have fixed my issue.
thanks again,
dave buckeyelake.org