Page 1 of 1
SOLVED: Generate session in UDT, possible ?
Posted: Tue Apr 12, 2011 7:50 am
by eus
Hello,
For a specific project i need a session in an udt. In this specific example i can't use frontendusers or other core packages.
So session_start() and assigning value's in the udt does not work like in native php. De variables are empty.
Should i store the session in global $gCms for example ?
Anyone experience with a custom session in a udt tag ?
Thnx
Re: Generate session in UDT, possible ?
Posted: Thu Jun 16, 2011 12:05 pm
by psy
In my limited php experience, session vars whether created in the content or via a UDT, dont take effect until the page is refreshed/redirected.
Is your session var called after a redirect?
Re: Generate session in UDT, possible ?
Posted: Thu Jun 16, 2011 8:22 pm
by vinyl
What code are you using exactly and where do you place it?
You can pass variables to a UDT and use that in a session, even from a module etc..
For example:
A sample UDT called "session":
Code: Select all
session_start();
$_SESSION['yoursession'] = $params['yourinput'];
echo $_SESSION['yoursession'];
The content on my page (here we capture the page title and pass it to our UDT,but that could be any module):
Code: Select all
{capture assign='test'}
{title}
{/capture}
{session yourinput=$test}
Re: Generate session in UDT, possible ?
Posted: Thu Jun 16, 2011 8:46 pm
by Jos
Don't know if it helps, but you don't necessarily need a UDT to display the value of a session. It can be done with Smarty directly
Code: Select all
{* display the php session variable "id" ($_SESSION['id']) *}
{$smarty.session.id}
http://www.smarty.net/docsv2/en/languag ... ty.request
Generate session in UDT, possible ?
Posted: Fri Jun 17, 2011 7:07 am
by eus
Hello,
Thanx for the suggestions. I've solved it by doing this in an UDT.
@session_regenerate_id() ;
$session=session_id() ;
It looks like session_start was already loaded in the cms