Unsettled session in smarty

After I insert data into the database, I set up a session and then redirect the page to another page, on another page I will show a message, if the session was set to smarty, everything is fine.

{if $smarty.session.insert===true}
      Thanks
{/if}

      

Now, how can I disconnect the session after I print my message?

+3


source to share


4 answers


You shouldn't be doing this in a template and smarty doesn't work for that. However, if you really need to do this, the only way I can see could be this:

{php}
    unset($_SESSION['insert']);
{/php}

      



Anything you put between the {php} tags will be executed by smarty like a normal php script.

+2


source


Smarty is a templating engine. It should n't handle session variables. You will need to do a unset($_SESSION['...'])

script in your PHP outside of Smarty.



0


source


You really shouldn't be doing this from a template, do it in PHP like below.

unset($_SESSION['session_var_name']);

      

If you really want to do it smart you have tried {$smarty.session.message|unset}

I don't know if this works, but it might be worth looking at.

0


source


In your php file where you display the smarty template, reverse it after the display function.

if(isset($_POST['postdata'])) {
  $_SESSION['insert'] = 'success';
}

$smarty->display('test.html');
unset($_SESSION['insert']);

      

In the template file

{if isset($smarty.session.insert)}
  {$smarty.session.insert}
{/if}

      

0


source







All Articles