CI' session question - 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: CI' session question (/showthread.php?tid=13609) |
CI' session question - El Forum - 11-29-2008 [eluser]chmod[/eluser] If i enable the item sess_use_database,set Code: $config['sess_use_database'] = TRUE; then CI will auot save user's session data in ci_session table. If I set the customer's session data , the data will be store in this table. Like this: Code: $this->session->set_userdata('islogin' => TRUE) I can get the customer's data: Code: $this->session->userdata('islogin'); but in another controller: I can't get the data,why? CI' session question - El Forum - 11-29-2008 [eluser]iainco[/eluser] Have you loaded the session library in the other controller? You should probably have the session library autoload. You can change that in your autoload.php Also, you have a syntax error with this code Code: $this->session->set_userdata('islogin' => TRUE) It should be: Code: $this->session->set_userdata(array('islogin' => TRUE)) or Code: $this->session->set_userdata('islogin', TRUE) CI' session question - El Forum - 11-29-2008 [eluser]chmod[/eluser] [quote author="iainco" date="1227999289"]Have you loaded the session library in the other controller? You should probably have the session library autoload. You can change that in your autoload.php Also, you have a syntax error with this code Code: $this->session->set_userdata('islogin' => TRUE) It should be: Code: $this->session->set_userdata(array('islogin' => TRUE)) or Code: $this->session->set_userdata('islogin', TRUE) I am sure loaded the session lib in autoload.php: Code: $autoload['libraries'] = array('database','session','form_validation'); and I set session like this: Code: $custom_session_data = array('username' => $this->input->post('username'), CI' session question - El Forum - 11-29-2008 [eluser]iainco[/eluser] Ok, that is all fine, can you show us the controller code where you can't seem to access the session data? CI' session question - El Forum - 11-29-2008 [eluser]chmod[/eluser] [quote author="iainco" date="1228002456"]Ok, that is all fine, can you show us the controller code where you can't seem to access the session data?[/quote] Yes,my code is bellow: login.php: Code: <?php mycenter.php: Code: <?php Model: Code: <?php my view: mycenter_tpl.php Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" in mycenter_tpl.php, the session data is displayed.but when I click the link: mybussiness I will redirect to the controller mybussiness Controller. But the session data can't access session data. Why? my mybussiness Controller: Code: <?php CI' session question - El Forum - 12-01-2008 [eluser]iainco[/eluser] Hi, sorry for taking so long to get back to you. In your login.php you have this code (function iloginto() for setting session data): Code: 'session_id_user' => $this->session->userdata('session_id') The session_id in CI sessions is automatically regenerated, I think the default is every 5 minutes. So when you try to access the other page where you are having problems, if the session has been regenerated, then you will be denied access. All the other session information will still be present and saved in the database but the session_id won't match. Maybe someone else will have a look and try and help! CI' session question - El Forum - 12-01-2008 [eluser]chmod[/eluser] Thanks to iainco. you are right.although I saved the session_id before,but he session updated, and CI's method gc deleted it.so I can't acess it.so, I resolved this problem: Edit the config.php: Step 1: Code: $config['sess_cookie_name'] = 'ci_session'; Step 2: decide gc: $config['sess_probability'] = 25; Step 3: edit lib's Session.php change: Code: if ((rand() % 100) < $this->gc_probability) to Code: if ((rand() % $this->CI->config->item('sess_probability')) < $this->gc_probability) Step 4: change: Code: setcookie( Code: setcookie( all these code resolved three things: 1:when I close browser's windows,the cookie will be delete. 2:CI's gc will work by myself; 3ession will not regen in short time. |