Welcome Guest, Not a member yet? Register   Sign In
unset_userdata
#1

[eluser]Colin Carter[/eluser]
Hello,

I'm not sure if I'm using unset_userdata() properly, but if I wanted to unset a number of session variables using an array unset_userdata() doesn't work.

For example:
Code:
$this->session->unset_userdata(array('name', 'data'));

doesn't unset the 'name' and 'data' session variables. This is, I believe, due to the line in unset_userdata() unsetting based on an array key not its value.

Code:
unset($this->userdata[$key]);

if I'm using unset_userdata() incorrectly please could you let me know how to use it. I read that it's been documented in svn but I couldn't find how to check it out.

Many thanks
#2

[eluser]johnwbaxter[/eluser]
The html page in the userguide
#3

[eluser]xwero[/eluser]
Is it already implemented in the current release? The current userguide doesn't have the unset_userdata section.
#4

[eluser]johnwbaxter[/eluser]
No the current userguide does not have it documented, the code is however present in the current released codebase (1.5.4) and you can use it just fine.
#5

[eluser]Colin Carter[/eluser]
There's also a typo in this documentation:

Quote:Removing Session Data

Just as set_userdata() can be used to add information into a session, unset_userdata() can be used to remove it, by passing the session key. For example, if you wanted to remove 'some_name' from your session information:

$this->session->unset_userdata('some_name');

This function can also be passed an array of items to unset.

$array_items = array('username', 'email');

$this->session->set_userdata($array_items);

Code:
$this->session->set_userdata($array_items);
shoud read:
Code:
$this->session->unset_userdata($array_items);

but this won't work because 'username' and 'email' are values and unset_userdata() unsets based on their keys (0 & 1)
#6

[eluser]johnwbaxter[/eluser]
Have you e-mailed derek allard to let him know?
#7

[eluser]Colin Carter[/eluser]
here's my fixed version:

Code:
function unset_userdata($newdata = array())
{
   if (is_string($newdata))
   {
      $newdata = array($newdata);
   }

   if (count($newdata) > 0)
   {
      foreach ($newdata as $val)
      {
         unset($this->userdata[$val]);
      }
   }

   $this->sess_write();
}
#8

[eluser]johnwbaxter[/eluser]
I suggest using OBsession, i use it and it works great.
#9

[eluser]Colin Carter[/eluser]
OBsession uses the same unset_userdata() function
#10

[eluser]johnwbaxter[/eluser]
Nice, i'll admit i haven't passed an array to that function yet. I'll have to bear this in mind.

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB