4

i am facing problem in x-cart, i am trying to create session and store value in x-cart for that, i used

x_session_register('subscription');

and the simple variable in it

$rs=1;
if($rs==1)
{
  $subscription=1;
}
else
{
  $subscription=0;
}

after that used some code in tpl file like,

{$smarty.session.subscription}

but nothing happen i also tried

{php}{/php}
$_SESSION[''];

but cant help me, i cant understand whats going wrong with that there is different file and template also file path is different try to create session in login.php and want this in head.tpl file please help me on that. thanks in advance

user3635340
  • 41
  • 1
  • 4

4 Answers4

2

Below, are some session variable-related notes, regarding x-cart 4.4.x branch.

With the x_session_register() function, each variable can be inserted in the $XCART_SESSION_VARS array and consequently, with the x_session_save() function, the session variables array is saved in the database.

Session data in xcart are saved in the xcart_session_data table, with primary key using the session id value of each visitor ('sessid' column) and all data being saved in serialized format in the 'data' column.

Example snippet:

if ($some_var == "Y"){
  x_session_register("my_var");  
  $my_var="true";
  x_session_save();
}

if($XCART_SESSION_VARS['my_var '] =="true")
  $smarty->assign("my_var", $my_var); 

In case the $XCART_SESSION_VARS variable is not in scope, we declare it as global and retrieve it.

tmarois
  • 2,424
  • 2
  • 31
  • 43
vasilis
  • 143
  • 1
  • 1
  • 13
1

In php file,

    if ($var1){
      x_session_register("my_var");  
      $my_var="content";
      x_session_save();
    }

    if($XCART_SESSION_VARS['my_var'] !=""){
      $smarty->assign("my_var", $XCART_SESSION_VARS['my_var']);
      x_session_unregister("my_var"); 
    }

in tpl file,

{if $my_var}
    {$my_var}
{/if}
Soorajlal K G
  • 778
  • 9
  • 20
0
// Try this in you php 
$smarty->assign('session',$_SESSION);

// OR in tpl
/*
{$session|print_r} // for above assignment

// OR
{php}
    print_r($_SESSION);
{/php}

// OR
{$smarty.session.*}

*/
kazimt9
  • 563
  • 5
  • 11
  • php and tpl are in different location, not asigned tpl in this php file. not working. – user3635340 May 14 '14 at 06:55
  • Did you print your session in any php file may be it helps to debug it. Are you sure your session exists and what happen when you print {$smarty.session.*} – kazimt9 May 14 '14 at 07:01
  • If your session exists so it must work according to http://www.smarty.net/docs/en/language.variables.smarty.tpl – kazimt9 May 14 '14 at 07:33
0

You should first check if there are any variables in $_SESSION. Run in PHP (not in Smarty) var_dump($_SESSION) to make sure there are any variables in it

I looked at documentation and seems x-cart doesn't store session variables in the way you think (so there won't be variables in $_SESSION). It doesn't store sessions in $_SESSION but in some custom ways. You can look at http://kb.x-cart.com/display/XDD/Sessions+management

As no data is in $_SESSION when you try to use $_SESSION in Smarty it won't work. You need to use x-cart methods to get session variables and then assign them to Smarty

tmarois
  • 2,424
  • 2
  • 31
  • 43
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291