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);
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\...
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....
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 ...
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 ...
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 ...
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.
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 ...
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.
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.
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 ...
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 ...
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. ...
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.
...
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 ...
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
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 ...
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 ...
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 = &...
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 ...
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 ...
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 ...
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',
'...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
session × 74users × 15
plugin-development × 9
control-panel × 8
login × 8
craft3 × 7
config × 7
cookies × 7
admin × 6
redis × 5
templating × 4
php × 4
current-user × 4
cache × 3
craft2 × 3
security × 3
timeout × 3
user-profile × 2
usermodel × 2
aws × 2
configuration × 2
entries × 1
plugin-craftcommerce × 1
localization × 1
database × 1