Hot answers tagged

12 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,315
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

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

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
4 votes
Accepted

How can I disable/decrease the number of calls to getAuthTimeout?

Unfortunately, the AJAX call to getAuthTimeout is hard coded to fire every 60 seconds. In other words, if you're looking for a config value, there isn't one – might be worth a feature request? For a ...
Mats Mikkel Rummelhoff's user avatar
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.2k
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

"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.2k
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,268
3 votes
Accepted

Using the CP login session expiration for the frontend

What you want is this: // Returns how many seconds are left in the current user session. // (int) The seconds left in the session, or -1 if their session // will expire when their HTTP session ends. ...
Ben Fleming's user avatar
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,071
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,767
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
  • 10.7k
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

Control Panel Session 60 second Timeout

I've had issues before where I was getting logged out and could not fathom why: it turned out (after weeks) that when I was using Inspector Tools' Responsive Design mode, Chrome sends different UA ...
Matt Wilcox's user avatar
  • 3,149
1 vote
Accepted

Craft cacheMethod setting is being overridden

The craft/config/memcache.php file has nothing to do with where PHP sessions are stored. It is for Craft's general purpose data caching. If you want to save PHP session in memcache, you'll need to ...
Brad Bell's user avatar
  • 67.2k
1 vote

Session destroy due to inactivity?

If you're running on Ubuntu, this will be relevant as well: The Case of the Missing PHP Session
andrew.welch's user avatar
  • 11.4k

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