Reputation: 928
I am using a system that needs to clear a select few SESSION variables. I am not certain that this is being done in the correct way as when going to back to certain pages the system seems to remember the last SESSION variables used. Perhaps it is the browser or something else entirely but I just wanted to check with someone else that this is best practice for clearing select variable. There seems to be a fair bit of info of using unset() in functions but none I have found apply directly to using unset() in a function with SESSION variables.
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';
}
Upvotes: 0
Views: 1048
Reputation: 4783
You're not unsetting the session, you're "setting" the session variable to nothing.
$_SESSION['SELL_with_reserve'] = '';
The following would unset the session:
unset($_SESSION['SELL_with_reserve']);
In addition, $_SESSION
is already global.
Also, as a side note, you might be better using a sub array, most certainly if you have other sessions.
Such as
$_SESSION['sell']['with_reserve']
$_SESSION['userdata']['username']
Then if you want to clear all sessions of a given type (ie all sell sessions but not userdata) you can just unset the entire sub session as such:
unset($_SESSION['sell']);
Leaving the $_SESSION['userdata']
intact.
Upvotes: 2