Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

$_SESSION is not updated

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
FrankTM
Smarty n00b


Joined: 19 Oct 2007
Posts: 3

PostPosted: Tue Jun 16, 2009 2:00 pm    Post subject: $_SESSION is not updated Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Jun 16, 2009 2:04 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jun 16, 2009 2:57 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
FrankTM
Smarty n00b


Joined: 19 Oct 2007
Posts: 3

PostPosted: Tue Jun 16, 2009 2:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jun 16, 2009 3:04 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
FrankTM
Smarty n00b


Joined: 19 Oct 2007
Posts: 3

PostPosted: Tue Jun 16, 2009 3:07 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP