已清除的SESSION变量未清除

时间:2013-12-08 15:23:38

标签: session-variables php

我正在使用一个需要清除少数几个SESSION变量的系统。我不确定这是以正确的方式完成的,因为当回到某些页面时,系统似乎记得使用的最后一个SESSION变量。也许它完全是浏览器或其他东西,但我只是想与其他人核实这是清除选择变量的最佳做法。似乎有很多关于在函数中使用unset()的信息,但我没有发现在使用SESSION变量的函数中直接应用unset()。

function unsetsessions()
{
global $_SESSION, $system;

$_SESSION['SELL_with_reserve'] = '';
$_SESSION['SELL_reserve_price'] = '';
$_SESSION['SELL_minimum_bid'] = ($system->SETTINGS['moneyformat'] == 1) ? 0.99 : '0,99';
$_SESSION['SELL_shipping_cost'] = 0;
$_SESSION['SELL_additional_shipping_cost'] = 0;
$_SESSION['SELL_file_uploaded'] = '';
$_SESSION['SELL_title'] = '';
$_SESSION['SELL_subtitle'] = '';
$_SESSION['SELL_description'] = '';
$_SESSION['SELL_pict_url'] = '';
$_SESSION['SELL_pict_url_temp'] = '';
$_SESSION['SELL_atype'] = '';
$_SESSION['SELL_iquantity'] = '';
$_SESSION['SELL_with_buy_now'] = '';
$_SESSION['SELL_buy_now_price'] = '';
$_SESSION['SELL_duration'] = '';
$_SESSION['SELL_currencies'] = '';
$_SESSION['SELL_relist'] = '';
$_SESSION['SELL_increments'] = '';
$_SESSION['SELL_customincrement'] = 0;
$_SESSION['SELL_shipping'] = 1;
$_SESSION['SELL_shipping_terms'] = '';
$_SESSION['SELL_selleraddy'] = '';
$_SESSION['SELL_international'] = '';
$_SESSION['SELL_sendemail'] = '';
$_SESSION['SELL_starts'] = '';
$_SESSION['SELL_action'] = '';
$_SESSION['SELL_is_bold'] = 'n';
$_SESSION['SELL_is_highlighted'] = 'n';
$_SESSION['SELL_is_featured'] = 'n';
$_SESSION['SELL_start_now'] = '';
$_SESSION['SELL_is_taxed'] = 'n';
$_SESSION['SELL_tax_included'] = 'y';
}

1 个答案:

答案 0 :(得分:2)

您没有取消会话,您将会话变量“设置”为空 $_SESSION['SELL_with_reserve'] = '';

以下内容将取消会话:

unset($_SESSION['SELL_with_reserve']);  

此外,$_SESSION已经是全球性的。

另外,作为附注,你可能更好地使用子数组,当然如果你有其他会话 如

$_SESSION['sell']['with_reserve']
$_SESSION['userdata']['username']

然后,如果要清除给定类型的所有会话(即所有销售会话但不是用户数据),您可以将整个子会话取消设置:

unset($_SESSION['sell']);

保持$_SESSION['userdata']完好无损。