Using nette session on legacy pages and issue to set expiration
- Jarda
- Member | 25
Hi guys,
I wanted to use nette forms on one old legacy page. When nette is loaded it
takes over session handling and I am not able to change expiration time. Here
is my code in bootstrap.
require_once FCE_DIR."/nette.min.php";
$session = \Nette\Environment::getSession();
$session->setExpiration(600);
var_dump(ini_get("session.gc_maxlifetime"));
When I load a page for the first time in the browser (with cleared cookies) it sets Expiration correctly to 600. When I reload the page before the time limit I get Nette\InvalidStateException: Unable to set ‘session.gc_maxlifetime’ to value ‘600’ when session has been started.
OK so I change the bootstrap and put expiration set up into condition
require_once FCE_DIR."/nette.min.php";
$session = \Nette\Environment::getSession();
if(!$session->isStarted())
$session->setExpiration(600);
var_dump(ini_get("session.gc_maxlifetime"));
When cookies are deleted and the page loaded the time is 600. After I reload the page the time is suddenly Nette's default 10800 (3 hours). How come Nette is able to set that time by itself when session was apparently already started and I cannot change it from the code?
Do you have any suggestions? could it be something on the server? I can reproduce the same on both local and hosting.
I was trying minified and normal version of Nette with the same results.
Nette Framework 2.0.4 (revision 2f3808e released on 2012–07–30)
Thanks for any hint.
- Jarda
- Member | 25
After a bit of experiments I was able to achieve my goal only by using neon config file.
common:
nette:
session:
autoStart: true
expiration: 10 minutes
and loading it in bootstrap
\Nette\Environment::loadConfig('config.neon');
But I would still wonder why using function setExpiration() doesn't work as expected.