Home > Blockchain >  Clear/destroy all session upon menu button click with smarty template
Clear/destroy all session upon menu button click with smarty template

Time:08-27

I know there is a tag to read the sessionsmarty.session.. tag but is there tag for destroying the session, like smarty.session.destroy?

What I want is when I click on menu button Data to destroy all stored sessions and start over with clean session.

This is the button that I have

<a href="/data.php" {if $smarty.server.PHP_SELF == "/data.php"}{/if}><span>{php}echo __('Data'){/php}</span></a>

I have session destroy in my PHP code where I detect if there is addition parameter in the URL to destroy it and re-load the page with clean session but I don't know if there is such thing for buttons. This is my php

if((isset($_GET['data'])) {     
    session_destroy();
    header("Location: data.php");
    exit;
}

So, if user is on https://example.com/data.php?data and refresh the page will load https://example.com/data.php with destroyed sessions.

How can I accomplish the same with the menu button click?

CodePudding user response:

Here is one quick (perhaps ugly) "hack". You can change your button like this:

<a href="/data.php?data" {if $smarty.server.PHP_SELF == "/data.php?data"}{/if}><span>{php}echo __('Data'){/php}</span></a>

This way you actually will pass the same parameter with the URL (like the one you expect in the if condition) and when you click on the button it will be cleaned and redirected to /data.php from the if condition. You will get one extra redirect on the button click.

  • Related