I have the following code in my module:
<?php
function MODULENAME_init() {
if (!user_is_logged_in()) {
global $user;
$user = user_load(31);
user_login_finalize();
}
}
Purpose of this code is to log in all anonymous user as user with id 31. But with this code i can't even logout correctly:
if (user_is_logged_in() && request_uri() == '/user') {
user_logout();
}
After i am visiting http://ggames.kz/user i am getting redirected back to the main page and so i am logged again as user 31. I want to log out any user when he's requesting http://ggames.kz/user and show a login form in order to log in as user with id 1.
hook_init
is the reason you can't log out. Because once you logout, it log in you back.