-
☆ A M B ☆
- 43 Posts
Hello fellow MODX'ers,
Does anyone know of a way to not set sessions for anonymous users?
I want anonymous users to not initiate a session and only have sessions for users who log in to the site.
I cannot set session_enabled to false in the context settings because then users who log in cannot receive a session.
how should modx know about a logged-in or not logged-in user without the initiated session?
I think you would need another context for private resources, which are meant only for logged-in users.
http://develop.modx.com/blog/2012/04/05/new-for-2.2.1-session-less-contexts/?utm_source=modx_forum&utm_medium=modx&utm_campaign=dev_blog&utm_content=sessionless_contexts
see Gotchas there
-
☆ A M B ☆
- 43 Posts
Yes, Know that a separate context would be the easy solution, however, I am looking for a solution where only users who log in gets a session without switching context.
I
There are a number of things (and some extras) that might not work properly without a session. Can you explain why you wouldn't want anonymous users to have a session? I can't think of any advantages to not having one.
Not writing a session to the session table for every anonymous user for example =), speeds MODX up quite a lot, but as was said in the comments above, this can be achieved with session_enabled = 0, but then you can't login anymore in this context, so the only solution is to move the private resources to another context. I'm not sure if it would be possible to basically have 2 separate context but with more or less the same configuration (e.g., base_url etc.), then the users wouldn't even recognize a difference...
Would that would work with all the extras that use hasSessionContext() to check the user's Login status?
Nope, unfortunately not for the context with session_enabled = 0, tried many things, but couldn't find a way...which extras do you mean particularly?
Nothing particular in mind, but I've seen that code often. If $modx->user is set, wouldn't either of these be a workable alternative?
if ($modx->user->get('username') === '(anonymous')) {
}
if ($modx->user->get('id') === 0) {
}
if sessions are disabled, this is always 0 as far as I remember =/
Quote from: exside at May 30, 2014, 09:33 PMif sessions are disabled, this is always 0 as far as I remember =/
For logged-in users too?