Forums / Developer / eZUser::isLoggedIn() is always true

eZUser::isLoggedIn() is always true

Author Message

John Moritz

Saturday 30 May 2009 5:44:29 am

I want to restrict a function for logged in user only. I thougt the eZUser::isLoggedIn() will help me for doing this.

if (eZUser::isLoggedIn())
{
    myCustomFunction();
}

But whatever i do (loged in or loged out), eZUser::isLoggedIn() is always true. It seems to me, that the anonymous user is also a "isLoggedIn" member.

When i am logged out, the code...

$user = eZUser::currentUser();
$userLogin = $user->attribute( 'login' );
echo $userLogin;

... will print "anonymous".
When i am logged in it will print the name of the loged in user, for example "admin".

Is this a bug, or is there another function which i can restrict a function for logged in users?
>> ezPublish 4.1.0

André R.

Sunday 31 May 2009 12:07:06 pm

This is probably casued by the know session bug in 4.1.0, please update the files to 4.1.2 and run the sql update files (oe + 4.1.1 + 4.1.2).

EDIT: You can of course dowload ezsession.php from svn as well to see if it helps first ( http://pubsvn.ez.no/nextgen/stable/4.1/lib/ezutils/classes/ezsession.php )

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

John Moritz

Tuesday 02 June 2009 12:53:25 am

I installed 4.1.2 (fresh not updating) but nothing changed. eZUser::isLoggedIn () is true whatever i do.
At the Moment i am doin it like this:

if (eZUser::currentUserID() > 14)
{
    myCustomFunction();
}

This is working now, but its dirty...

Gaetano Giunta

Tuesday 02 June 2009 1:16:09 am

Just to make it 'a little bit cleaner': if your check is done in the pagelayout, you will have the global var $anonymous_user_id (see http://ez.no/doc/ez_publish/technical_manual/4_0/templates/the_pagelayout/variables_in_pagelayout ) to compare against, instead of hardcoding "!= 14" in your templates...

Principal Consultant International Business
Member of the Community Project Board

John Moritz

Friday 05 June 2009 6:03:22 am

I have to make my user check in the PHP File, because it will then check data which was sended by a html <form>.

Can someone explain how i can restrict something (in php file) for a Usergroup? Maybe that will solve my problem.

André R.

Friday 05 June 2009 10:28:51 am

A couple of things I overlooked the first round.
* isLoggedIn is not static, you need to get the user instance before you can use it.
* if we actually talk about eZUser::isUserLoggedIn here, then make sure you supply the user id you want to check as parameter and continue the discussion in this thread if it doesn't work: http://ez.no/developer/forum/setup_design/automatically_logout_user_after_some_period_of_inactivity

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

John Moritz

Saturday 06 June 2009 4:05:17 am

Andre, you are right!
First i didnt realised that isloggedin is not static. After reading the api reference yesterday, i solved this issue.

Thank you very much!

Horst Lindlbauer

Wednesday 18 May 2011 7:31:10 am

The following method returns true for anonymous as well,  isUserLoggedIn being a static function:

$userId = eZUser::currentUserID();
eZUser::isUserLoggedIn($userId);

The only reliable method to get loggedin-information seems to be:

$user = eZUser::currentUser();
$user->isLoggedIn();

---------------------------------------
http://www.lbm-services.de