Welcome Guest, Not a member yet? Register   Sign In
Help: Having set_userdata issues
#1

[eluser]fserrano[/eluser]
I'm having problems setting a session value. If I set the session to a string value, when I go to another page in the site it will remember the session value. However, if I set the session value to a query result, it won't store the value at all. Any ideas? Here it is in code:

The following works. It will save the value "MyString" in the session (I'm using database cookie).

Code:
$query = $this->db->get_where('projects',array('nickname'=>$this->uri->segment(4)));
$newid='MyString';
$this->session->set_userdata('currentprojectid',$newid);

But the following won't work. It will not save any value to the session:

Code:
$query = $this->db->get_where('projects',array('nickname'=>$this->uri->segment(4)));
$newid=$query->row()->id;
$this->session->set_userdata('currentprojectid',$newid);
#2

[eluser]BrianDHall[/eluser]
Run a var_dump on $newid, I'm guessing it isn't what you are expecting.
#3

[eluser]fserrano[/eluser]
var_dump($newid) shows string(1) "3". What does that mean?

Here is the code
Code:
$query = $this->db->get_where('projects',array('nickname'=>$this->uri->segment(4)));
$newid=$query->row()->id;
var_dump($newid);
$this->session->set_userdata('currentprojectid',$newid);
#4

[eluser]bretticus[/eluser]
My guess is that your query object stores a resource link to a database connection (the var_dump should shed some light on that.) I would also assume that serialize() is used the the CI session algorithm. resource types cannot be serialized.

EDIT: Whoops, I read your post again. Apparently you were not trying to store the query object. Sorry if I confused you.
#5

[eluser]bretticus[/eluser]
[quote author="fserrano" date="1253611418"]var_dump($newid) shows string(1) "3". What does that mean?[/quote]

It means you have a string of length 1 and the value is "3." Doesn't make a whole lot of sense why "3" cannot be serialized across page loads to me. Shouldn't be a problem. Perhaps you can post your code that displays where you attempt to use the session data.
#6

[eluser]fserrano[/eluser]
In the code that displays it I am essentially just echoing the session variable. Haven't gone beyond that yet since I noticed the error.

Code:
$data['maincontent']="<p>Current project is ".$this->session->userdata('currentprojectid')."</p>";
#7

[eluser]BrianDHall[/eluser]
Hrm - right below you set the userdata maybe try

Code:
var_dump($this->session->userdata('currentprojectid');

If $newid is just a string with the contents '3', and your sure it works when you use the earlier code you posted where you just assign a string directly, I'm not sure what the problem could be. It would have to be elsewhere (a debugger would really come in handy here).
#8

[eluser]fserrano[/eluser]
I tried to change things around and still am getting the same results. To simplify, I did this
Code:
$this->session->set_userdata('currentprojectid',$this->uri->segment(3));
where $this->uri->segment(3) is a number. Then, if I echo the session in another page
Code:
echo "<p>Current project is ".$this->session->userdata('currentprojectid')."</p>";
I get "js". Reviewing the ci_sessions table I see
Code:
"currentprojectid";s:2:"js";
What am I missing here? Should I report a bug?

I should add that I can successfully add session user data upon login in my login.php controller. It is only after I am logged in that in the project.php controller I cannot set this new userdata.
#9

[eluser]bretticus[/eluser]
[quote author="fserrano" date="1253666293"]
I get "js". Reviewing the ci_sessions table I see
Code:
"currentprojectid";s:2:"js";
What am I missing here?[/quote]

Show us the URL please.
#10

[eluser]fserrano[/eluser]
I should add that I can successfully add session user data upon login in my login.php controller. It is only after I am logged in that in the project.php controller I cannot set this new userdata.




Theme © iAndrew 2016 - Forum software by © MyBB