...

View Full Version : 4.3.2 and unsetting a session var?



Íkii
09-08-2003, 07:19 PM
session_start();
if(is_array($_SESSION) && count($_SESSION) > 0)
{
foreach($_SESSION AS $var=>$val)
{
$_SESSION[$var] = '';
unset($_SESSION[$var]);
$GLOBALS[$var] = '';
unset($GLOBALS[$var]);
session_unregister($var);
global $$var;
$$var = '';
unset($$var);
}
}
session_unset();
setcookie (session_name(), '', (time () - 2592000), '/', '', 0);
session_destroy();

You might be able to guess from that, that I've been trying for a while to either set the value to '' or totally unset the particular session variable.
I have used the above in an auto-redirecting (session-killer) page and in a main page that doesn't redirect.
A page on the site with

if(isset($_SESSION['varname']) && $_SESSION['varname'] != '')
{
// this gets executed after all the unsetting
}

has the session var miraculously reappear.

The buglist has a few references, most of which are slammed down as 'bogus' without any of the php developers actually informing how to unset a session variable so that it isn't accessible on the next page.

buglist search (http://bugs.php.net/search.php?search_for=unset+session&boolean=0&limit=10&order_by=&direction=ASC&cmd=display&status=All&php_os=&phpver=&assign=&author_email=&bug_age=0)
4.3.2 bug notice (http://bugs.php.net/bug.php?id=24270)

Any ideas?

Íkii
09-08-2003, 10:14 PM
A fair few hours down the line (and a few less hairs on the ol' head) and I gave up with using sessions for that bit and moved to using $_GET.

mordred
09-09-2003, 12:33 AM
Normally you just delete a variable from a $_SESSION array like this:

unset($_SESSION['varname']);

I'm still dicyphering your code though - not that easy at all. A few general hints that might point at the source of the confusion:

1. Don't use session_register, session_unregister if you use $_SESSION. There are strange cases where they cause trouble if used in the same script, yours might be one of them.

2. foreach() operates on a copy of the original array.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum