Forums / Developer / how to check if this user is logged in?

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

how to check if this user is logged in?

Author Message

zaxofeel .v

Sunday 10 July 2005 3:02:22 am

hey ppl, how are you all? :)
as usual, i need ur help,
i want to check if the current user is logged in or not, so, i found this piece of code in one of the ez templates:

 {section show=eq($current_user.contentobject_id,$anonymous_user_id)}

      <a class="menuitem" href={"/user/login/"|ezurl}>{"Login"|i18n("design/standard/layout")}</a>

      {section-else}

      <a class="menuitem" href={"/user/logout/"|ezurl}>{"Logout"|i18n("design/standard/layout")}</a> ({content_view_gui view=text_linked content_object=$current_user.contentobject})

      {/section}

when i used this code, i found that it always displays "login", and it never displayes logout even if i am already signed in.

i really hope if someone can tell me what's wrong with that or if there is another way to implement this, i'll be very thankful.
thanks all

Pål J Didriksen

Sunday 10 July 2005 5:48:07 am

Hi!

I think you need to fetch the current user first, for example:

{default current_user=fetch('user','current_user')}

Then you can show different content, depending on wether the user is logged in or not:

{default current_user=fetch('user','current_user')}
{section show=$current_user.is_logged_in}
    Hello, {$current_user.contentobject.name}, you are now logged in!   
{section-else}
    Please log in first.
{/section}
{/default}

Hope this works for you too!

Pål J.

zaxofeel .v

Monday 11 July 2005 12:49:28 am

thank you very much dear friend
the line of fetching the current user was what i am missing
problem solved.
thanks again :)