|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
FrankTM Smarty n00b
Joined: 19 Oct 2007 Posts: 3
|
Posted: Tue Jun 16, 2009 2:00 pm Post subject: $_SESSION is not updated |
|
|
scenario:
$_SESSION contains info
$smarty instance is created
$_SESSION is updated
$smarty->display() is called
$smarty shows old data
testcase with various php versions:
[url goes herem but i'm not allowed to post those yet]
As you can see, I don't write to the session from within the template.
It must have something to do with the superglobal changes.
I'm not sure this is a desired change though.
You should not be able to do changes in $_POST, $_GET and $_REQUEST, but I think at least $_SESSION should be up to date when $smarty->display() or $smarty->fetch() is called. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Jun 16, 2009 2:04 pm Post subject: |
|
|
FrankTM has a test case here http://scriptzone.nl/~frank/smarty_testcase-sessions/ that shows the change of behaviour in Smarty-2.6.24.
funnily the change is in 2.6.24 and not in 2.6.23 where "make PHP super globals read-only from template" was introduced.
What was the reason behing making super globals read-only anyway? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jun 16, 2009 2:57 pm Post subject: |
|
|
Changing session variables in-template is a security issue, and not something that should be done from a template anyways.
example:
{$smarty.session.foo++} |
|
Back to top |
|
FrankTM Smarty n00b
Joined: 19 Oct 2007 Posts: 3
|
Posted: Tue Jun 16, 2009 2:59 pm Post subject: |
|
|
that's pretty much what I said, and what my testcase does.
I do not update the $_SESSION vars from within the template, but just from ordinary php. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jun 16, 2009 3:04 pm Post subject: |
|
|
Yes it makes an internal copy of the globals to use in-template at instantiation. This is a sticky issue, I'll have look into it further. As a workaround you can assign yourself:
Code: | $smarty->assign_by_ref('SESSION',$_SESSION); |
Then you can use {$SESSION.foo} in your templates. |
|
Back to top |
|
FrankTM Smarty n00b
Joined: 19 Oct 2007 Posts: 3
|
Posted: Tue Jun 16, 2009 3:07 pm Post subject: |
|
|
mohrt wrote: | Yes it makes an internal copy of the globals to use in-template at instantiation. This is a sticky issue, I'll have look into it further. As a workaround you can assign yourself:
Code: | $smarty->assign_by_ref('SESSION',$_SESSION); |
Then you can use {$SESSION.foo} in your templates. |
thanks for the quick replies
that workaround is quite a lot better then what i've came up with |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|