# Login fails silently, seems to be a session problem

**URL:** <https://community.modx.com/t/login-fails-silently-seems-to-be-a-session-problem/6654>\
**Category:** Support\
**Tags:** login, revo-3\
**Created:** [April 21, 2023, 8:41am UTC](https://community.modx.com/t/login-fails-silently-seems-to-be-a-session-problem/6654 "2023-04-21T08:41:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![moduser](https://community.modx.com/user_avatar/community.modx.com/moduser/32/2817_2.png) [@moduser](https://community.modx.com/u/moduser)\
**Post date:** [April 21, 2023, 8:41am UTC](https://community.modx.com/t/login-fails-silently-seems-to-be-a-session-problem/6654/1 "2023-04-21T08:41:22Z")

</div>

Hi! I hope you can help me out with this

### Summary

I had a working 3.03-pl MODX manager, but I cleared my cookies while logged in. Now I am unable to log in again. When I use the log in page nothing happens, it simply reloads. This behavior seems similar to these other open topics on this site: [Upgrade issues can not login](https://community.modx.com/t/upgrade-issues-can-not-login/6635) and [After upgrade from 3.0.1 to 3.0.2 manager not works](https://community.modx.com/t/after-upgrade-from-3-0-1-to-3-0-2-manager-not-works/6214)

### Debug Attempts

I have cleared the `core/cache` with ftp and my `core/cache/logs/error.log` says:

`(ERROR @ ...core/src/Revolution/modUser.php : 393) PHP warning: session_regenerate_id(): Session ID cannot be regenerated when there is no active session`  
and  
`(ERROR @ .../core/src/Revolution/modManagerRequest.php : 107) PHP warning: Undefined variable $_SESSION`

I have also emptied my `modx_session` table and noticed that `modx_active_users` is empty while `modx_manager_log` is recording every login as if it were successful. My `session_handler_class` is set to `MODX\Revolution\modSessionHandler`

I have tried from different browsers and private/incognito windows. The browser console returns no errors, and no cookies/sessions

 ![Screen Shot 2023-04-21 at 04.04.07](https://modx-community.s3.dualstack.us-east-1.amazonaws.com/original/2X/8/8512b90cb00797ada34be417e541c37037f67589.png)

What should I try next?

### Environment

Apache 2.4, PHP 8.0, MariaDB 10.3, Firefox 112.

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [April 21, 2023, 9:22am UTC](https://community.modx.com/t/login-fails-silently-seems-to-be-a-session-problem/6654/2 "2023-04-21T09:22:14Z")

</div>

You could try setting `session_handler_class` to blank, to use ‘standard PHP session management’.  
There are also other settings (starting with `session_cookie_...`) that you could try changing.

Always clear the cache (`core/cache`) after changing a system setting in the database.

---

<div class="post-metadata">

**Author:** ![moduser](https://community.modx.com/user_avatar/community.modx.com/moduser/32/2817_2.png) [@moduser](https://community.modx.com/u/moduser)\
**Post date:** [April 22, 2023, 3:57am UTC](https://community.modx.com/t/login-fails-silently-seems-to-be-a-session-problem/6654/4 "2023-04-22T03:57:35Z")

</div>

Thank you for your suggestions! I tried using the PHP session handler by setting `session_handler_class` to blank and got a similar error in the PHP error log about `$_SESSION` being undefined from line `11 of /index.php`

I also tried different `session_cookie` system settings, always clearing the cache, with both PHP and MODX session handlers to no avail. These were `session_cookie_httponly`, `session_cookie_secure`, `session_cookie_domain`, and `session_cookie_path`

When I found `session_enabled` I recalled that I had experimented with contexts, and deleted the 3 test contexts I had made from `mod_access_context` and `mod_context` (none had `mod_context_setting`s). I also made sure that the `default_context` was `web`.

However, none of this changed the problem. This glitch fascinates me, but I might just start from a fresh install because I can’t make any progress with it.

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [April 22, 2023, 8:20am UTC](https://community.modx.com/t/login-fails-silently-seems-to-be-a-session-problem/6654/5 "2023-04-22T08:20:28Z")

</div>

> [@moduser](#):
>
> error in the PHP error log about `$_SESSION` being undefined

This probably means that the PHP function [session\_start](https://www.php.net/manual/en/function.session-start.php) either doesn’t get called at all or is not successful.

- Is the system setting `anonymous_sessions` set to `true`?
- When you call `session_start();` in a test PHP file, does that work?

---

<div class="post-metadata">

**Author:** ![moduser](https://community.modx.com/user_avatar/community.modx.com/moduser/32/2817_2.png) [@moduser](https://community.modx.com/u/moduser)\
**Post date:** [April 22, 2023, 8:27pm UTC](https://community.modx.com/t/login-fails-silently-seems-to-be-a-session-problem/6654/6 "2023-04-22T20:27:41Z")

</div>

Interesting! I wrote and executed a script that called `session_start()` without issue. Then I tried logging in, and _it worked!_ This made me terribly suspicious, so I tried logging out again, which recreated the problem.

In other words, you seem to be correct that `session_start` is either not being called or failing when MODX calls it.

`anonymous_sessions` _was_ set to `0` (`false`) so I changed it to `1` and cleared the cache. Doing this **fixed the log in issues** , and I can imagine why. I can now log in and logout and even clear my cookies without this issue recurring.

However, I expect that breaking login is an unintended consequence of turning off anonymous sessions. Shouldn’t the login page still generate a session? I prefer to have sessions off for the main site.

Thinking that this might be a bug, I tested on a clean install (at the same host) and it created the same log in issue. As far as I can tell, the only thing necessary to create this problem is changing the system setting `anonymous_sessions` to No.

While this might be a bug with `anonymous_sessions` or unique to my host, my particular issue has definitely been solved 🎊 Thank you @halftrainedharry for your succinct and prompt troubleshooting assistance!

For anyone with the same issue: As a workaround to keep session cookies off the main site I set [`session_enabled`](https://docs.modx.com/current/en/building-sites/settings/session_enabled) to No for the `web` context which worked nicely, setting `anonymous_sessions` to No for `web` worked as well. I found the workaround on [this closed issue](https://github.com/modxcms/revolution/issues/12983#issuecomment-219218179) from modx 2.5.

These were the issues that resembled my problem, both closed:

- [Modx 2.5 "anonymous\_sessions" = 0 prevents logging in to the Manager · Issue #12983 · modxcms/revolution · GitHub](https://github.com/modxcms/revolution/issues/12983)
- [Cannot regenerate session id - session is not active · Issue #13742 · modxcms/revolution · GitHub](https://github.com/modxcms/revolution/issues/13742)

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [April 23, 2023, 9:26am UTC](https://community.modx.com/t/login-fails-silently-seems-to-be-a-session-problem/6654/7 "2023-04-23T09:26:45Z")

</div>

I was able to recreate the issue as well. I think it’s a bug, as the behavior in MODX 2.x is different.  
I opened an issue on Github:

> <https://github.com/modxcms/revolution/issues/16424>
>
> \## Bug report
> \### Summary
> When the system setting \`anonymous\_sessions\` is set …to \`No\`, it's no longer possible to log in to the MODX manager (when the cookies are cleared beforehand).
> 
> \### Step to reproduce
> In MODX 3, set the system setting \`anonymous\_sessions\` to \`No\`. Clear the browser cookies. Then try to log in to the manager.
> 
> \### Observed behavior
> Sending the login form, just reloads the page.
> 
> In MODX 2.x this is not the case, but I couldn't figure out what the difference between the versions is.
> When you log in, the "security/login" processor gets executed and a redirect happens. In MODX 2.x \`$\_COOKIE\` has content after the redirect, in MODX 3 \`$\_COOKIE\` is still empty.
> 
> https://github.com/modxcms/revolution/blob/69a7d6d14f84151ced04a552678657456c05b9cc/core/src/Revolution/modX.php#L2793
> 
> \### Environment
> MODX 3.0.3

---

<div class="post-metadata">

**Author:** ![system](https://community.modx.com/user_avatar/community.modx.com/system/32/2_2.png) [@system](https://community.modx.com/u/system)\
**Post date:** [April 25, 2023, 9:27am UTC](https://community.modx.com/t/login-fails-silently-seems-to-be-a-session-problem/6654/8 "2023-04-25T09:27:06Z")

</div>

Closed on April 25, 2023, 9:27am UTC

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.
