Jump to content

[SOLVED] destroying sessions


CaptainChainsaw

Recommended Posts

Hi all, I've got an irritating problem which is probably needs an easy fix.

 

I have a "logoff.php" script which I simply want it to kill the session and display a message to the user saying that they have been successfully logged out.  The problem is that when I click the "log off" link it produces no message to the user unless the the page is refreshed.

 

Here's my code:

 

<?
session_start();
session_destroy();
include('header.php');
require('/home/vol4/byethost12.com/b12_2105146/htdocs/smarty/Smarty.class.php');
require_once('class.conf.php');


$conf=new conf();
$smarty = new Smarty();
$smarty->template_dir = $conf->getConfItem('template_dir');
$smarty->compile_dir = $conf->getConfItem('compile_dir');
$smarty->cache_dir = $conf->getConfItem('cache_dir');
$smarty->config_dir = $conf->getConfItem('config_dir');


if(!$_SESSION['username']){
			$smarty->assign('loggedoff', 'You have been sucessfully logged off.');
			$smarty->display('logoff.tpl');
}
include('footer.php'); 
?>

 

 

Any ideas?

 

Thanks again for any help on this one.

 

CC :)

Link to comment
https://forums.phpfreaks.com/topic/116855-solved-destroying-sessions/
Share on other sites

Try taking out the if conditonal statement; if(!$_SESSION['username']){ and simply display the message without it.

 

More than likely the $_SESSION['username'] variable still exists until the next page load. You could also simply do:

 

session_destroy(); unset($_SESSION['username'])

 

However the 1st example would probably be best.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.