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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 04:29:54
Script start
Timing: Jan 18 2025 04:29:54
Module start 'layout'
Timing: Jan 18 2025 04:29:54
Module start 'content'
Timing: Jan 18 2025 04:29:55
Module end 'content'
Timing: Jan 18 2025 04:29:55
Script end

Main resources:

Total runtime1.2997 sec
Peak memory usage4,096.0000 KB
Database Queries76

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0047 589.3516152.6250
Module start 'layout' 0.00470.0025 741.976639.4453
Module start 'content' 0.00731.2909 781.4219675.6016
Module end 'content' 1.29820.0014 1,457.023420.1563
Script end 1.2996  1,477.1797 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00300.2277160.0002
Check MTime0.00130.1025160.0001
Mysql Total
Database connection0.00080.062610.0008
Mysqli_queries1.236095.1010760.0163
Looping result0.00080.0650740.0000
Template Total1.268997.620.6345
Template load0.00180.140920.0009
Template processing1.267197.487520.6335
Template load and register function0.00010.011010.0001
states
state_id_array0.00200.154410.0020
state_identifier_array0.00190.146520.0010
Override
Cache load0.00160.1230410.0000
Sytem overhead
Fetch class attribute can translate value0.00050.037440.0001
Fetch class attribute name0.00180.1385100.0002
XML
Image XML parsing0.00140.106240.0003
class_abstraction
Instantiating content class attribute0.00000.0017110.0000
General
dbfile0.00090.0693230.0000
String conversion0.00000.000640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 36
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs