Skip to main content
13 votes

Can you save a variable in session?

And for those needing this for Craft 3... Set (previously called 'add'): Craft::$app->getSession()->set($key, $value); Get Craft::$app->getSession()->get($key);
Mark Notton's user avatar
  • 2,337
7 votes

How can I store Craft sessions in the database?

To store sessions in the DB in Craft 3, you can merge the following into your config/app.php file: return [ 'components' => [ 'session' => [ 'class' => yii\web\...
Jeff T's user avatar
  • 81
5 votes

Using PHP Redis as Session Store

This may help: Add the following to the general.php 'cacheMethod' => 'redis', 'overridePhpSessionLocation' => 'tcp://localhost:6379' Add the following to the index.php ini_set('session....
berkayunal's user avatar
5 votes

Limit number of sessions per user

Im on Craft v3.4.25, and I've added the following event handler in my module to handle this. There are two scenarios here: either you want the new login to invalidate any existing session, or you want ...
Gary Reckard's user avatar
5 votes

Keep on getting logged out when deploying using Capistano

The problem is that the basepath changes each time you deploy (Capistrano uses versioned release directories). The basepath is used to generate a session key, which is invalidated each time a new ...
Richard Frank's user avatar
5 votes
Accepted

How to inform the front-end user that their session is about to expire?

You can check the remaining time in the session with JavaScript using Craft's users/session-info controller action. This endpoint returns an object like this as a JSON response: { "isGuest&...
MoritzLost's user avatar
  • 11.5k
4 votes

Implementing SimpleSAML PHP in Craft plugin

We managed to circumvent the issue by using the sql session storage SimpleSAML PHP also provides. Not a real solution but a viable workaround.
Frank Zwiers's user avatar
4 votes
Accepted

How can I store Craft sessions in the database?

In Craft 3.4, you can run the craft setup/php-session-table console command. That will create a phpsessions table in the database with the proper schema for MySQL or PostgreSQL. Then from your ...
Brad Bell's user avatar
  • 67.5k
4 votes
Accepted

Can I manage/change the default flash message text?

You could for example just edit the translation file with the specific user registered flash message. You can read more about the static translation in the docs.
Christopher Dosin's user avatar
3 votes
Accepted

Getting error "Your session has ended. Enter your password to log back in." every 30 seconds or so

Thanks for the troubleshooting help. It appears as though the issue was the cache and how Craft handles sessions. For those who use a cache/CDN and are having issues with control panel session ...
Ian O'Brien's user avatar
3 votes

conditional does not run first in a file that is included using the extends feature for twig

The issue here is that extends isn't the same thing, neither conceptually or technically, as an include. When you extend a template with a layout template, the template is "decorated" by the layout. ...
André Elvan's user avatar
  • 7,288
3 votes
Accepted

"Your session has ended" modal popping up constantly

Thanks to Brad's help, we discovered that the server was misconfigured with an incorrect value for session.cookie_domain. Fixing that resolved the issue in this case.
Derek Hogue's user avatar
3 votes
Accepted

How can I disable sessions for most of my Craft site?

I'm not sure there is going to be an easy way to do this in Craft 2, unfortunately. In the upcoming Craft 3, we refactored the session logic so that a session will only get started on requests that ...
Brad Bell's user avatar
  • 67.5k
3 votes

Getting session Id in twig template

Old post, I know, but we've recently published a plugin to achieve this for a similar problem we were facing. SessionExposer plugin can help you achieve this. To get the Session ID in the template ...
Mutual's user avatar
  • 442
3 votes
Accepted

Is it safe to remove the craft/storage/runtime/sessions folder?

Docs runtime/ – Pretty much everything in here is there for caching and logging purposes. Nothing that Craft couldn’t live without, if the folder happened to get deleted. It is safe to delete it
Robin Schambach's user avatar
3 votes
Accepted

Craft CMS 3 - Redis Sessions cause error

@boboldehampsink to the rescue: https://github.com/craftcms/cms/issues/3428 Update: This article covers things really well. https://nystudio107.com/blog/the-case-of-the-missing-php-session php ini ...
Tim Kelty's user avatar
  • 3,081
3 votes
Accepted

Is it possible to change the amount of time a user stays logged in for?

Yes! The setting is called userSessionDuration, and you can set it in your general.php config file, on a per-environment basis. Here's an explanation of the values that you can use for the setting—for ...
August Miller's user avatar
3 votes

500 Internal error on admin - session related

I found it. There were some files in my web folder that had the reference to session.save variable with that old path for php7. Both .user.ini and php.ini had the following line: session.save_path = &...
Rodney Little's user avatar
3 votes

How does Craft CMS handle user's session with Redis

I partially try to answer my question but It's still unclear to me why session table is used for storing user's session data too. For reference I use PostgreSQL database and "fluent" style ...
Dominik Krulak's user avatar
2 votes

Getting logged out of admin area when refreshing site

As Brad Bell mentioned in this answer: It can be that wherever Apache/PHP is configured to save session files doesn't exist or isn't writable. If you've got the overridePhpSessionLocation config ...
Simon East's user avatar
2 votes

"Your session has ended" modal popping up constantly

Try all of the above suggestions first, then... If you've added the configuration of 'defaultCookieDomain' to /craft/config/general.php as I did, you may see this error. I'm using MAMP which has no ...
Vaughn D. Taylor's user avatar
2 votes
Accepted

Craft 2 Commerce 1 cart session expiry

Create a commerce.php config file in your config folder and set the cartCookieDuration to a time interval. The default is 3 months. <?php return [ 'cartCookieDuration' => 'P3M', '...
Luke Holder's user avatar
  • 6,837
2 votes
Accepted

How to make a curl request with a session to an action url?

You don't want to use a separate web request to call the controller action of Craft Commerce. This has numerous downsides beyond your current problem with the missing session. It will negatively ...
MoritzLost's user avatar
  • 11.5k
2 votes
Accepted

How to group SESSION values?

When you save a value to the session using an existing key, Craft (or rather, Yii) will assume that the new value (an array, in your case) should replace any existing value, for that key. I.e. there's ...
Mats Mikkel Rummelhoff's user avatar
2 votes
Accepted

Custom module controller: how to impersonate any user and start its session

Technically, there is no real "impersonation" in Craft. All the "impersonate" action in the CP does, is to log in the currently logged-in user as a different user; albeit with some ...
Mats Mikkel Rummelhoff's user avatar
2 votes
Accepted

Session token error/missing after server switch

That session path is related to cPanel with an Easy Apache install with multiple php binaries. For an error message to display that cPanel session path locally, there must be a session path hard-coded ...
colonelclick's user avatar
1 vote
Accepted

Migrated site - now dashboard keeps logging out

I contacted the hosting company and they managed to fix the issue. They whitelisted the cookie name in their varnish caching system.
Dan B's user avatar
  • 21
1 vote

Migrated site - now dashboard keeps logging out

Sounds to me like a server config issue. The site worked in one place, you moved it, and now you have this issue. If it's an Nginx server, this may be helpful: Nginx-Craft
andrew.welch's user avatar
  • 11.6k
1 vote

Migrated site - now dashboard keeps logging out

I'm not sure if 774 would be enough permissions on that folder. If the web server is not running as the account user (via ruid or suexec/suphp), or is not in the same group as the account user then it ...
Rick Kukiela's user avatar
1 vote

Migrated site - now dashboard keeps logging out

Just a question; are you on a Nginx server? I had a similar issue before with a client site. the Nginx configuration was removing the cookies when it cached the page, which redirected to the login ...
lpbouvier's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible