Help: Having set_userdata issues - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Help: Having set_userdata issues (/showthread.php?tid=22838) |
Help: Having set_userdata issues - El Forum - 09-21-2009 [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))); 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))); Help: Having set_userdata issues - El Forum - 09-21-2009 [eluser]BrianDHall[/eluser] Run a var_dump on $newid, I'm guessing it isn't what you are expecting. Help: Having set_userdata issues - El Forum - 09-21-2009 [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))); Help: Having set_userdata issues - El Forum - 09-21-2009 [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. Help: Having set_userdata issues - El Forum - 09-21-2009 [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. Help: Having set_userdata issues - El Forum - 09-21-2009 [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>"; Help: Having set_userdata issues - El Forum - 09-22-2009 [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). Help: Having set_userdata issues - El Forum - 09-22-2009 [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)); Code: echo "<p>Current project is ".$this->session->userdata('currentprojectid')."</p>"; Code: "currentprojectid";s:2:"js"; 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. Help: Having set_userdata issues - El Forum - 09-22-2009 [eluser]bretticus[/eluser] [quote author="fserrano" date="1253666293"] I get "js". Reviewing the ci_sessions table I see Code: "currentprojectid";s:2:"js"; Show us the URL please. Help: Having set_userdata issues - El Forum - 09-22-2009 [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. |