Solution for Magento 2.1+
Since Magento 2.1 the admin session lifetime is always "session", i.e. until the browser is closed. This has been might have been introduced for security reasons.
The relevant code is in Magento\Backend\Model\Session\AdminConfig
:
/**
* Set session cookie lifetime to session duration
*
* @return $this
*/
protected function configureCookieLifetime()
{
return $this->setCookieLifetime(0);
}
If you want to change this behavior, you can add a plugin for this class with the following interceptor method:
public function beforeSetCookieLifetime()
{
$lifetime = $this->scopeConfig->getValue(
\Magento\Framework\Session\Config::XML_PATH_COOKIE_LIFETIME,
\Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
return [$lifetime, \Magento\Framework\Session\Config::COOKIE_LIFETIME_DEFAULT];
}
Where $this->scopeConfig
should be an instance of \Magento\Framework\App\Config\ScopeConfigInterface
, injected via constructor parameter.
This way the cookie lifetime is used from configuration, just as in the frontend.
Note that the configuration in Stores > Configuration > Advanced > Admin Security > Session Lifetime does not have any effect on the cookies anymore! It is used to determine Redis session lifetime, so if you increase the cookie lifetime, you should also increase this value.
would you be interested in adjusting the functionality of the layered navigation on our M2 website? – Els den Iep – 2016-07-13T13:51:19.957
@ElsdenIep pls. find my contact information in the profile – Arkadii Chyzhov – 2016-07-27T19:51:47.717
Do you know what is the column in the database for that value, so I can change it programmatically? – jojman – 2016-08-16T16:57:40.410
I've set it to be 50400 but it still logs out after around 20 mins.... – OZZIE – 2016-09-13T14:18:41.577
@ArkadiiChyzhov see my answer below :) – OZZIE – 2016-09-14T14:30:00.543