Welcome Guest, Not a member yet? Register   Sign In
Session Library another Error
#1

[eluser]Zorancho[/eluser]
Hi all.
I found this website where some of the guys from CodeIgniter is having a tutorial about protection using the session library.
His code was something like this:
Code:
class User extends Controller
{
   function User
   {
      parent::Controller();
      if($this->session->userdata('hash_string'))
      {
      $this->session->userdata(array('last_hash_string' =>   $this->session->userdata('hash_string')));
      }
    $this->load->helper('string');
    $this->session->userdata(array('hash_string' => random_string('alnum', 6)));
}
And then he puts the hash_string from the session into a hidden input that he checks with the form_validation library if it is the same with the last_hash_string...
But when i try it i get this error:
Severity: Warning

Message: Illegal offset type in isset or empty

Filename: libraries/Session.php

Line Number: 422

And that line is:
Code:
function userdata($item)
{
    return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item];
}
If hash_string it's not isset then return false, otherwise it should return the value of it. But i don't get it why it doesn't see the given argument as valid.
Any ideas?
Thanks in advance
#2

[eluser]pistolPete[/eluser]
You need to use the function set_userdata()!
Please see the user guide:
Quote:Adding Custom Session Data
...
To add your data to the session array involves passing an array containing your new data to this function:
Code:
$this->session->set_userdata($array);


Code:
if($this->session->userdata('hash_string'))
{
    $this->session->set_userdata(array('last_hash_string' =>   $this->session->userdata('hash_string')));
}
$this->session->set_userdata(array('hash_string' => random_string('alnum', 6)));




Theme © iAndrew 2016 - Forum software by © MyBB