Jump to content

Clearing Out SESSION


doubledee

Recommended Posts

They're generally both used to say, "hey, there's nothing useful in this session value any more."  Which one you use might be determined by the code being used to check if there is a useful value to be had.

 

For example, one script might simply check for the presence of a particular key in the $_SESSION array; if it's there then the author might have chosen to assume there is an okay value for use when he needs it.  Another script might prefer to keep that key present in the array but with a specific value to raise the same flag as the other script did by removing the key entirely. 

 

if (array_key_exists('blah', $_SESSION))
// versus
if ($_SESSION['blah'] !== '')

 

I wouldn't stress over which to choose, so long as it ties in with what your script is expecting of an empty/missing/unset session value.

Hopefully this illustrates the difference...

$foo['bar'] = 'bleh';

var_dump($foo); // array(1) { ["bar"]=> string(4) "bleh" } 

$foo['bar'] = '';

var_dump($foo); // array(1) { ["bar"]=> string(0) "" } 

unset($foo['bar']);

var_dump($foo); // array(0) { } 

That means we should use the function unset() to clear the session data. Else if we simply set it like this $_SESSION['value'] = ''; rather than using unset() function it will consider there is a session value existing. We can understand this thing from "scootstah" post.

 

 

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.