eZ Community » Forums » Developer » How to manually logout a user ?
expandshrink

How to manually logout a user ?

How to manually logout a user ?

Tuesday 15 November 2011 3:29:07 pm - 3 replies

Hello,

I would like to manually logout a user I fetch by its login but I do not find any logout() method in eZUser class.

I've tried the eZUser::logoutCurrent() but the client sending the request to the view does not know the session. So it does not work.

Do you have any idea ?

Tuesday 15 November 2011 6:59:38 pm

Hmm tricky one if you the client doesn't know the session.

Maybe you can try something like:

  • edit the 'User' class and add a new attribute 'User last session ID'
  • create a new login handler that updates that attribute in the user object with the current session ID after successful login.
  • then, when required, switch to the session using the saved session ID and do a logout

Good luck

Tuesday 15 November 2011 7:40:47 pm

OK,

my view has changed. I now receive the sessionID.

How can I use it to logout the user ?

Tuesday 15 November 2011 7:41:28 pm

If you are using database-based session storage, deleting all existing sessions given a user id is trivial (look at ezsession table definition).

For native-php-based session storage, you will have to resort to something like Huy says (but take care: what if 2 sessions are open in parallel for the same user?) or scan the filesystem where sessions are stored looking for the user-id in the serialized session data, which can be quite time and resource-consuming

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from