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

eZ debug

Timing: Jan 18 2025 02:11:02
Script start
Timing: Jan 18 2025 02:11:02
Module start 'content'
Timing: Jan 18 2025 02:11:03
Module end 'content'
Timing: Jan 18 2025 02:11:03
Script end

Main resources:

Total runtime0.9685 sec
Peak memory usage4,096.0000 KB
Database Queries213

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0096 588.8359180.8281
Module start 'content' 0.00960.8163 769.6641680.6797
Module end 'content' 0.82590.1425 1,450.3438340.4297
Script end 0.9684  1,790.7734 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00450.4606210.0002
Check MTime0.00160.1608210.0001
Mysql Total
Database connection0.00110.108510.0011
Mysqli_queries0.879490.80602130.0041
Looping result0.00220.22522110.0000
Template Total0.933496.420.4667
Template load0.00180.184120.0009
Template processing0.931696.194020.4658
Template load and register function0.00020.016910.0002
states
state_id_array0.00150.154810.0015
state_identifier_array0.00080.084920.0004
Override
Cache load0.00150.1572410.0000
Sytem overhead
Fetch class attribute can translate value0.00160.163150.0003
Fetch class attribute name0.00130.1322100.0001
XML
Image XML parsing0.00130.136050.0003
class_abstraction
Instantiating content class attribute0.00000.0020110.0000
General
dbfile0.00540.5571340.0002
String conversion0.00000.005030.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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