By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,705 Members | 2,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,705 IT Pros & Developers. It's quick & easy.

unset($_SESSION['var']) fails

P: n/a
PHP:
unset($_SESSION['mainDisplay']);

In my original environment (PHP 4.3.2) this line will delete the
session variable 'mainDisplay'. But in the testing environment (PHP
4.3.6) the variable persists even after unset() is called.

Is there some special setting in PHP that can allow a session to
persist even if you attempt to delete it? I am only able to delete the
session variable upon closing the browser and rebooting computer.

Thanx
Phil
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Phil Powell wrote:
PHP:
unset($_SESSION['mainDisplay']);


<?php
session_start();

if (isset ($_SESSION['mainDisplay']) ) {

$_SESSION['mainDisplay'] = array();

}
?>

HTH,
Best regards,
Sebastian
--
The most likely way for the world to be destroyed,
most experts agree, is by accident.
That's where we come in; we're computer professionals.
We cause accidents.
--Nathaniel Borenstein
Jul 17 '05 #2

P: n/a
apologies for top-posting, i just need to get this rant out of the way
first:

sebastian - please make sure you quote the message to which you
replying in such a way as to make any further comments
understandable... for this reason i've inserted the original question
below, indented with pipes (|)
On Fri, 23 Jul 2004 19:50:34 +0200, Sebastian Lauwers
<?dacrashanddie?no?@?spam?9online.fr?> wrote:
|PHP:
| unset($_SESSION['mainDisplay']);
|
|In my original environment (PHP 4.3.2) this line will delete the
|session variable 'mainDisplay'. But in the testing environment (PHP
|4.3.6) the variable persists even after unset() is called.
|
|Is there some special setting in PHP that can allow a session to
|persist even if you attempt to delete it? I am only able to delete the
|session variable upon closing the browser and rebooting computer.

<?php
session_start();

if (isset ($_SESSION['mainDisplay']) ) {

$_SESSION['mainDisplay'] = array();

}
?>


and how is this meant to help?

the OP asked why his $_SESSION variable was not getting unset when he
asked it to ... assigning an empty array to the variable in question
is /not/ really a fix to the problem.

OP: RTM (http://www.php.net/manual/en/function.unset.php)

specifically the User Contributed Notes as follows:

[quote php.net]

andre at twg dot com dot au
07-Mar-2004 02:16

Only This works with register_globals being 'ON'.

unset( $_SESSION['variable'] );

The above will not work with register_globals turned on (will only
work outside of a function).

$variable = $_SESSION['variable'];
unset( $_SESSION['variable'], $variable );

The above will work with register_globals on & inside a function

[/quote php.net]

Jul 17 '05 #3

P: n/a
Herbie Cumberland <sp******@skipraider.com> wrote in message news:<sd********************************@4ax.com>. ..

The above will not work with register_globals turned on (will only
work outside of a function).

$variable = $_SESSION['variable'];
unset( $_SESSION['variable'], $variable );

------------------------------------------------------------------------------

The caveat being "Work outside of a function". Sorry, but this has to
occur within a class method, therefore, it doesn't work.

What I found that does work, however, has been denounced by the PHP
community at large, but not a single person can explain WHY this works
in spite of the fact that the Manual says you can't:

[PHP]
print_r(ini_get('register_globals'))); echo '<p>';
if ((int)ini_get('register_globals') === 1)
ini_set('register_globals', false);
session_cache_limiter();
session_start();
print_r(ini_get('register_globals'))); echo '<p>';
[/PHP]

In PHP 4.3.6 with register_globals ON this happens:

1
It successfully turned off register_globals, and I was able to, within
my class method, successfully delete the session variable:

[PHP]
unset($_SESSION['mainDisplay']);
[/PHP]

I even tested in the other server which is PHP 4.3.2 with
register_globals OFF and it works; turned it ON, it still worked!

Phil
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.